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

Collection.find does not work in 7.6.1 if filter attribute is set to none #278

Closed
sushi2all opened this issue Aug 31, 2023 · 3 comments
Closed

Comments

@sushi2all
Copy link

sushi2all commented Aug 31, 2023

Hello,

I have a piece of code searching for records that DO NOT have a certain attribute, in the following way:

match = dict(
 canceled = None, 
 #...some other stuff
)
cursor = self.tx.collection('Whatever').find(match)

This was working fine up to a while ago. Today a customer called me saying that a feature wasn't working. I had just upgraded to the latest version of python arango, and using a previous version the bug didn't appear (I know, I should have tests in place, I'll get to them someday 😓).

The error is the following:

arango.exceptions.DocumentGetError: [HTTP 400][ERR 1501] AQL: syntax error, unexpected none modifier near 'None\n LIMIT 0, nu...' at position 3:69 (while parsing)

I looked weird that it mentioned a query. I checked the python-arango code and noticed that in the latest release the code for find changed in 022afc2 from this:

data: Json = {
    "collection": self.name,
    "example": filters,
    "skip": skip,
}
if limit is not None:
    data["limit"] = limit

request = Request(
    method="put", endpoint="/_api/simple/by-example", data=data, read=self.name
)

def response_handler(resp: Response) -> Cursor:
    if not resp.is_success:
        raise DocumentGetError(resp, request)
    return Cursor(self._conn, resp.body)

return self._execute(request, response_handler)

to this

skip_val = skip if skip is not None else 0
limit_val = limit if limit is not None else "null"
query = f"""
    FOR doc IN @@collection
        {build_filter_conditions(filters)}
        LIMIT {skip_val}, {limit_val}
        RETURN doc
"""

bind_vars = {"@collection": self.name}

request = Request(
    method="post",
    endpoint="/_api/cursor",
    data={"query": query, "bindVars": bind_vars, "count": True},
    read=self.name,
    headers={"x-arango-allow-dirty-read": "true"} if allow_dirty_read else None,
)

def response_handler(resp: Response) -> Cursor:
    if not resp.is_success:
        raise DocumentGetError(resp, request)
    return Cursor(self._conn, resp.body)

return self._execute(request, response_handler)

@aMahanna: Is this a regression or dict(attribute=None) as filter is not meant to work? In the second case, is there any other solution or workaround?

@aMahanna
Copy link
Member

Hi @sushi2all, the fix for this has been addressed in #277

Will be triggering a 7.6.2 release now, so this should solve the issue

@aMahanna
Copy link
Member

7.6.2 released: https://pypi.org/project/python-arango/7.6.2/

@sushi2all
Copy link
Author

Thank you!

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

2 participants