Giter Club home page Giter Club logo

couchdb3's People

Contributors

n-vlahovic avatar setop avatar tschoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

couchdb3's Issues

server::up() swallows exceptions

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:

  • response body is or is not "status" in res_json.keys() and res_json["status"] == "ok"
  • response code is or is not not 404

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!

Follow the API?

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.