-
Notifications
You must be signed in to change notification settings - Fork 93
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
Optional Embedded model and key_name not working #484
Comments
the 'working' workarounds were tested by calling |
I have another field on the parent subscriptions: Optional[list[Subscription]] = Field(default_factory=list) and class Subscription(EmbeddedModel):
company_id: Optional[str] = Field(None, key_name="companyId") ...it doesn't seem to have the same problem So maybe the |
No... if I remove the the difference above is that |
shouldn't there by some stuff with |
I can see that Odmantic also doesn't respect the this explains why my application unit tests didn't catch the issue above before we deployed the change - the tests generate test data via the Odmantic model so it was creating records that it could read |
Why did the people supporting odmantic make changes to the model configuration. It was perfect when it was flexible. Years of working with models and MongoDB collection/document. Then Type Error replaces working model. No existing documentation just failure. To be honest I thought the schema key/value pair followed by another class statement with Config: collection = 'mycollection' was simple and flexible. Now it seems I have to add a 'model_config and add another JSON structure to reference my collection and that throws another error on a field with key not found but I can see it in the object returned. Yes BSON based on JSON is a key/value pair structure. But this is obscuring terms and not needed. We have ObjectID but many of use don't use it. I do most of my queries on fields. Simply listed as key/value pairs for a model which is data that I choose to use. The whole idea of a repository tool is the flexibility to map to data and validate in the code. Not have the repository tool set outside requirements in mapping to a database table/collection or document. No we have to rewrite the code base and that is a problem. New ideas about conforming to some standard that breaks 100,000 lines of code is not the way. Set the new standards but don't break the code. |
Bug
I have the following model:
It was working before I made the
company_relations
fieldOptional
(which I had to because sometimes the key is missing in MongoDB records)When I try to fetch valid records I now get errors like:
Notably the
companyId
field exists in the input.If I remove the
Optional
it works (but can't cope with missing field).If I replace
company_id: str = Field(key_name="companyId")
withcompanyId: str # noqa: N815
and keep theOptional
it works.So it seems to be the combination of
Optional
+key_name
that has the problem.Current Behavior
See above.
Also I can instantiate the
CompanyRelation
directly from the sub data (again bypassing whatever theOptional
on parent model has done to break things)Expected behavior
No error.
Environment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: