-
Notifications
You must be signed in to change notification settings - Fork 92
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 EmbeddedModel not working #370
Labels
bug
Something isn't working
Comments
@carlosfrutos Did you find a way to work around? I currently have the same problem: class miniSeriesDTO(EmbeddedModel):
losses: int
progress: str
target: int
wins: int
class LeagueEntry(Model):
leagueId: str
queueType: str
tier: TierEnum
rank: RankEnum
leaguePoints: int
wins: int
losses: int
hotStreak: bool
veteran: bool
freshBlood: bool
inactive: bool
miniSeries: Optional[miniSeriesDTO] = None |
Are there any updates or workarounds? |
@renja-g import traceback
from typing import List
from odmantic import Model, EmbeddedModel, Field, Reference
class Error(EmbeddedModel):
code: int = Field(500)
message: str = Field("Internal Server Error")
class Document(Model):
text: str = Field(...)
error: List[Error] = Reference(key_name="dsError")
try:
print(Document(text="This is a test", error=[]).doc())
except Exception as e:
print(traceback.format_exc())
try:
print(Document(text="This is a failure", error=[Error(code=404, message="Not found")]).doc())
except Exception as e:
print(traceback.format_exc()) Output: {'text': 'This is a test', 'error': [], '_id': ObjectId('661e929c48b2346427e89de1')}
{'text': 'This is a failure', 'error': [{'code': 404, 'message': 'Not found'}], '_id': ObjectId('661e929c48b2346427e89de2')} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug
Somehow related to #350 with both situations I faced and I couldn't solve.
Current Behavior
Raises Exception in both cases. Happens in all versions starting from 0.9.0
Expected behavior
It should create the document, regardless "error" has a valid value or is None. This was working in version 0.8.0. It stopped working from 0.9.0 and keeps happening in 0.9.2.
Environment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):The text was updated successfully, but these errors were encountered: