You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone, I was trying to figure out how to properly use choices in a given field when defining a schema and I'm not sure if I've stumbled into something or if I'm misunderstanding the intended behaviour.
all goes as expected, validation succeeds because 'foo' is one of the admissible choices and I can check in the database that the document is there with the job_status field populated.
Now the part that puzzles me. If I update the field to an invalid value:
mock_document.update(job_status='whatever')
then the update succeeds without any validation errors, and I can see in the database that the document has indeed changed to have an invalid status.
So my first question would be: I've noticed that when updating the document there is a call to the validate method of the field's subclass (in the example StringField.validate) but I'm wondering if it would be preferable to call BaseField._validate instead? It seems that this way it would call BaseField._validate_choices along the way?
But this leads to the second question. When manually enforcing this validation:
mock_document.validate()
no errors are raised either, and the reason is that mock_document._data.get('job_status') is still 'foo'. How come there is a mismatch in this field between the value as stored in mock_document and the value as stored in the database?
I hope the example makes sense, I've kept it as bare-bones as possible. Any help with this would be greatly appreciated!
PS: I am using mongoengine v0.27.0.
The text was updated successfully, but these errors were encountered:
Hi everyone, I was trying to figure out how to properly use
choices
in a given field when defining a schema and I'm not sure if I've stumbled into something or if I'm misunderstanding the intended behaviour.Say I have something as simple as this:
If I now create and save a valid document:
all goes as expected, validation succeeds because
'foo'
is one of the admissible choices and I can check in the database that the document is there with thejob_status
field populated.Now the part that puzzles me. If I update the field to an invalid value:
then the update succeeds without any validation errors, and I can see in the database that the document has indeed changed to have an invalid status.
So my first question would be: I've noticed that when updating the document there is a call to the
validate
method of the field's subclass (in the exampleStringField.validate
) but I'm wondering if it would be preferable to callBaseField._validate
instead? It seems that this way it would callBaseField._validate_choices
along the way?But this leads to the second question. When manually enforcing this validation:
no errors are raised either, and the reason is that
mock_document._data.get('job_status')
is still'foo'
. How come there is a mismatch in this field between the value as stored inmock_document
and the value as stored in the database?I hope the example makes sense, I've kept it as bare-bones as possible. Any help with this would be greatly appreciated!
PS: I am using mongoengine
v0.27.0
.The text was updated successfully, but these errors were encountered: