2

Eve API. I need to filter records by where={"uuid": "my_uuid"}. So my 'settings.py' for the Eve application contains:

'schema': {
        'uuid': {
             'type': 'string',
             'required': True,
             'query_objectid_as_string': True,
             'data_relation': {
                 'resource': 'users',
                 'field': 'uuid',
                 'embeddable': True
             }
         }
    }

When I try to write something by API call, I get error:

cerberus.schema.SchemaError: {'uuid': [{'query_objectid_as_string': ['unknown rule']}]}

Python3.6, Eve 1.1, Cerberus 1.3.2

What I am doing wrong?

Alex
  • 98
  • 7

1 Answers1

1

Eve's query_objectid_as_string is part of Resource customization. You need to move it from Schema configuration to Domain configuration. See the docs for more:

Schema - https://docs.python-eve.org/en/stable/config.html#schema-definition

Domain - https://docs.python-eve.org/en/stable/config.html#domain-configuration

gcw
  • 1,639
  • 1
  • 18
  • 37
  • Hmm, I have moved `query_objectid_as_string` to domain configuration, and cerberus stops to throw error, so, thank you. But filtration does not work yet. Can you suggest to check anything else? – Alex Mar 24 '20 at 13:08
  • 1
    No problem. Does it return nothing or http 404? Could you post the request URL you are trying? – gcw Mar 24 '20 at 17:20
  • It rerurns code 200 OK, but with emty "_items": [] in response. URL: `http://localhost:6000/drivings?where={"uuid": "0KLQsNGA0LDQvdC+0LJf0KHQsNGI0LBfXzIzLTA4LTE5ODg="}` – Alex Mar 24 '20 at 18:51
  • That's curious. What would be the schema definition for `users`? – gcw Mar 25 '20 at 11:37
  • I have posted related issue here: https://github.com/pyeve/eve/issues/1371 – Alex Mar 25 '20 at 15:06
  • 1
    May be unrelated, but is it necessary to have `query_objectid_as_string` = `true` in this case? I mean, the uuid contents are not a 24-bit hex, it is base64, so I think eve would not try to convert it to an ObjectId. – gcw Mar 25 '20 at 16:33
  • Yes, you were right ) Thank you once again! Inside database "uuid" looks like a string, no ObjectId specifiers for that field. And this have brought me to the idea about incompatibility between my base64 encoded "uuid" and URL. And guess what? A sign "+" inside uuid was that reason – Alex Mar 25 '20 at 20:15
  • 1
    Nice, glad you found it! – gcw Mar 26 '20 at 12:41