Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching docs in view by key/keys parameter #57

Open
conduct0 opened this issue Jan 9, 2025 · 1 comment
Open

Fetching docs in view by key/keys parameter #57

conduct0 opened this issue Jan 9, 2025 · 1 comment

Comments

@conduct0
Copy link

conduct0 commented Jan 9, 2025

Hey,

thank you for the work in this library.

I run into a small issue while querying documents in a view by key. Since there are no docs yet I will quote the code. I use Couchdb v. 3.1.1

The problem happens In the View class in view.py where some methods like ids and docs are made available.

In ids method we have keys parameter. In that case we fetch with POST as described in the couchdb docs. This works.

async def ids(
        self,
        keys: Optional[List[str]] = None,
        prefix: Optional[str] = None,
        **params: Any,
    ) -> AsyncGenerator[str, None]:
(...)

In docs method we have ids parameter instead of keys like above. If I put keys in ids param it works as above.

async def docs(
        self,
        ids: Optional[List[str]] = None,
        create: bool = False,
        prefix: Optional[str] = None,
        include_ddocs: bool = False,
        **params: Any,
    ) -> AsyncGenerator[Document, None]:
(...)

If I pass keys=["A_KEY"] or key it makes a GET request. The keys or key get added to the query string like so:

aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', (...)/_view/by_configuration_type?key=access_point_configuration&include_docs=true

(...)/_view/by_configuration_type?keys=access_point_configuration&include_docs=true

# After testing with curl this is the error returned by those requests:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

The correct way of sending those requests would be:

(...)/_view/by_configuration_type?key=%22access_point_configuration%22&include_docs=true
(...)/_view/by_configuration_type?keys=%5B%22access_point_configuration%22%2C%22by_real_estate%22%5D&include_docs=true

I think there are two issues. Internally, in these functions, keys and ids is used interchangeably. The second issue is, how params are url encoded in the GET request. Maybe deciding on either POST or GET requests internally would reduce the surface to implement stuff.

Hope this helps, if I got something wrong please let me know.

@conduct0 conduct0 changed the title Fetching docs in view by key parameter naming Fetching docs in view by key/keys parameter Jan 9, 2025
@conduct0
Copy link
Author

conduct0 commented Jan 9, 2025

I found that the problem with url encoding maybe occurs because of how aiohttp encodes params dict. See here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant