Skip to content

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

Closed
@sushi2all

Description

@sushi2all

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions