n-vlahovic / couchdb3 Goto Github PK
View Code? Open in Web Editor NEWA Python wrapper around the CouchDB API
License: MIT License
A Python wrapper around the CouchDB API
License: MIT License
Hi,
First, thanks for the work you've dedicated to this package. It helped me to implement a new system much more quickly than if I had had to code the client side of the API on my own.
I ran into an issue that I think would be pretty easy to address.
In my situation, I was calling Server.up()
with a mangled url. In order to figure this out I had to trace into the code and look at the url. The problem is easy enough to solve. But it strikes me that a bad url should have given me an exception.
The root of the problem is the implementation of Server.up()
:
def up(self) -> bool:
"""
Check if the server is up.
Returns
-------
bool : `True` if the server is up.
"""
try:
self._get(resource="_up")
return True
except (CouchDBError, requests.exceptions.RequestException):
return False
According to the documentation, the response from the server if it is up is:
{"status":"ok"}
If the server is in maintenance mode, the request results in a 404.
Since there are an arbitrary number of conditions besides these that could indicate a problem, it is not accurate to base this method's return value on there being any exception.
To satisfy my curiosity, I did a quick rewrite as follows:
try:
self._get(resource="_up")
return True
except CouchDBError as ex:
import ipdb; ipdb.set_trace()
return False
except requests.exceptions.RequestException as ex:
import ipdb; ipdb.set_trace()
return False
My request landed on the request exception with NameResolutionError
: the mangled url had no dns lookup.
It seems to me that the normal path to determine the return value of this function is:
"status" in res_json.keys() and res_json["status"] == "ok"
Otherwise, any exceptions should be allowed to bubble up to the caller: there are many things that could go wrong besides the _up
endpoint's result.
If this approach sounds useful, I would be happy to take a crack at a re-write and a unit test and to submit a pull request. Just let me know.
Many thanks!
Hi,
would you like to follow some API for this project?
I am writing python APIs for no-sql databases, such as CouchDB, based on the SQL database APIs.
If you are interested, I could fork the project and adapt it to the APIs (classes and methods) I wrote.
Link: nosqlapi
Thanks!
Hello,
Can you add in the documentation the samples for fetching documents, views and how to make the queries? Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.