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

'id' based query other than of type ObjectId is returning None #370

Open
PraveenKumarPalai opened this issue Mar 11, 2022 · 1 comment
Open

Comments

@PraveenKumarPalai
Copy link

PraveenKumarPalai commented Mar 11, 2022

This is the issue that I am facing:

ResultsModel.find_one({ 'order.customer.id': customer_id, 'order_source': order_source, })

returns None

Whereas,

ResultsModel.find_one({ 'order.customer.customer_id': customer_id, 'order_source': order_source, })
(using customer_id instead of id (same value)) works - returns Data

Or

ResultsModel.find_one({ 'order.customer.email': customer_email, 'order_source': order_source, })

returns Data

Here, order.customer.id is of type int
and order is of type fields.DictField()

Note: Creating Embedded Docs. work, but in my case orders is a complex nested structure and it may have varying structures so cannot fix the schema. Hence using fields.DictField() instead of fields.EmbeddedField()

@PraveenKumarPalai
Copy link
Author

Looked up the code:

Here are my observations:

Looked up the umongo library code, looks like we are using a recursive filed mapper, and the default name of primaryKey ( _id ), is put as id. Hence this matches our type and converts every id (not embedded fields) to _id, Hence due to filed mismatch we don't get back the data.

Removing the below snippet returns data as we are not fetching the matching attribute anymore.

(Updated logic)
Screenshot 2022-03-12 at 3 53 33 AM

(Existing logic with some logs (added by me))
Screenshot 2022-03-12 at 3 55 21 AM (1)

But looks like the problem can have a permanent solution by naming the _id filed as _id only (in the library implementation) and not id.

@PraveenKumarPalai PraveenKumarPalai changed the title 'id; based query other than of type ObjectId is returning None 'id' based query other than of type ObjectId is returning None Mar 12, 2022
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