handle default issue with multiple inheritance#687
Merged
slorello89 merged 3 commits intoredis:mainfrom Apr 4, 2025
Merged
Conversation
slorello89
reviewed
Apr 4, 2025
tests/test_hash_model.py
Outdated
| assert rematerialized.bio is None | ||
|
|
||
| @py_test_mark_asyncio | ||
| async def test_grandchild_class_expression_proxy(): |
Member
There was a problem hiding this comment.
These tests pass on the current state of main, I see what you are getting at though, you are talking about multiple inheritance - so if you try to run this test on main:
@py_test_mark_asyncio
async def test_multiple_inheritance_class_expression_proxy():
class Model(HashModel):
first_name: str
last_name: str
age: int = Field(default=18)
bio: Optional[str] = Field(default=None)
class Sibling():
is_sibling: bool = Field(default=True)
class Child(Model, Sibling):
is_child: bool = True
await Migrator().run()
m = Child(first_name="Steve", last_name="Lorello")
assert m.age == 18
await m.save()
assert m.age == 18
assert m.is_sibling
assert m.is_child
rematerialized = await Child.find(Child.pk == m.pk).first()
assert rematerialized.age == 18
assert rematerialized.age != 19
assert rematerialized.bio is None
assert rematerialized.is_sibling
assert rematerialized.is_childit will fail
Collaborator
Author
There was a problem hiding this comment.
Yes, that is exactly it. I updated the test to reflect that. I wasn't totally understanding what the issue was on our side but now that I do, we can definitely fix it in our implementation. Either way, wanted to leave this up in case it is helpful.
slorello89
reviewed
Apr 4, 2025
aredis_om/model/model.py
Outdated
| model_fields = getattr(bases[base_index], "model_fields", []) | ||
| for f_name in model_fields: | ||
| field = model_fields[f_name] | ||
| print(field) |
Member
There was a problem hiding this comment.
Would you mind deleting this extra print while you are in here?
Member
There was a problem hiding this comment.
I tried to push a commit removing it to your branch but my push was rejected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is something we can handle in our implementation but, we wanted to put this up in case it would be helpful to others.
Prior to the pydantic 2.0 change, we were able to define abstract classes as
RedisModel's and then, in implementation we could define whether we wanted it to be aHashModelor aJsonModel. After the change, any defaults we had were coming through asExpressionProxyobjects for the models with the mixins.This fix handles multiple bases on a model to prevent this from happening.