Skip to content

Commit df495c5

Browse files
committed
update test to reproduce error
1 parent 23e7bd1 commit df495c5

File tree

2 files changed

+21
-44
lines changed

2 files changed

+21
-44
lines changed

tests/test_hash_model.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Migrator,
1919
NotFoundError,
2020
QueryNotSupportedError,
21+
RedisModel,
2122
RedisModelError,
2223
)
2324

@@ -977,39 +978,27 @@ class Child(Model):
977978
assert rematerialized.age == 18
978979
assert rematerialized.bio is None
979980

981+
980982
@py_test_mark_asyncio
981-
async def test_grandchild_class_expression_proxy():
983+
async def test_child_class_expression_proxy_with_mixin():
982984
# https://github.com/redis/redis-om-python/issues/669 seeing weird issue with child classes initalizing all their undefined members as ExpressionProxies
983-
class Model(HashModel):
985+
class Model(RedisModel, abc.ABC):
984986
first_name: str
985987
last_name: str
986988
age: int = Field(default=18)
987989
bio: Optional[str] = Field(default=None)
988990

989-
class Child(Model):
990-
other_name: str = "test"
991-
992-
class GrandChild(Child):
993-
grand_name: str = "test"
994-
995-
class GreatGrandChild(GrandChild):
996-
great_name: str = "test"
991+
class Child(Model, HashModel):
992+
other_name: str
993+
# is_new: bool = Field(default=True)
997994

998995
await Migrator().run()
999-
m = GreatGrandChild(first_name="Steve", last_name="Lorello")
1000-
assert m.age == 18
996+
m = Child(first_name="Steve", last_name="Lorello", other_name="foo")
1001997
await m.save()
1002-
998+
print(m.age)
1003999
assert m.age == 18
1004-
assert m.other_name == "test"
1005-
assert m.grand_name == "test"
1006-
assert m.great_name == "test"
10071000

1008-
rematerialized = await GreatGrandChild.find(GreatGrandChild.pk == m.pk).first()
1001+
rematerialized = await Child.find(Child.pk == m.pk).first()
10091002

10101003
assert rematerialized.age == 18
1011-
assert rematerialized.age != 19
10121004
assert rematerialized.bio is None
1013-
assert rematerialized.other_name == "test"
1014-
assert rematerialized.grand_name == "test"
1015-
assert rematerialized.great_name == "test"

tests/test_json_model.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Migrator,
2222
NotFoundError,
2323
QueryNotSupportedError,
24+
RedisModel,
2425
RedisModelError,
2526
)
2627

@@ -1160,7 +1161,6 @@ class TestLiterals(JsonModel):
11601161
assert rematerialized.pk == item.pk
11611162

11621163

1163-
11641164
@py_test_mark_asyncio
11651165
async def test_two_false_pks():
11661166
from pydantic_core import PydanticUndefined as Undefined
@@ -1171,6 +1171,7 @@ class SomeModel(JsonModel):
11711171

11721172
SomeModel(field1="foo", field2="bar")
11731173

1174+
11741175
@py_test_mark_asyncio
11751176
async def test_child_class_expression_proxy():
11761177
# https://github.com/redis/redis-om-python/issues/669 seeing weird issue with child classes initalizing all their undefined members as ExpressionProxies
@@ -1195,42 +1196,30 @@ class Child(Model):
11951196
assert rematerialized.age != 19
11961197
assert rematerialized.bio is None
11971198

1199+
11981200
@py_test_mark_asyncio
1199-
async def test_grandchild_class_expression_proxy():
1200-
# https://github.com/redis/redis-om-python/issues/669 seeing weird issue with child classes initalizing all their undefined members as ExpressionProxies
1201-
class Model(JsonModel):
1201+
async def test_child_class_expression_proxy_with_mixin():
1202+
class Model(RedisModel, abc.ABC):
12021203
first_name: str
12031204
last_name: str
12041205
age: int = Field(default=18)
12051206
bio: Optional[str] = Field(default=None)
12061207

1207-
class Child(Model):
1208-
is_new: bool = True
1209-
1210-
class GrandChild(Child):
1211-
is_newer: bool = True
1212-
1213-
class GreatGrandChild(GrandChild):
1214-
is_great: bool = True
1208+
class Child(Model, JsonModel):
1209+
is_new: bool = Field(default=True)
12151210

12161211
await Migrator().run()
1217-
m = GreatGrandChild(first_name="Steve", last_name="Lorello")
1218-
assert m.age == 18
1212+
m = Child(first_name="Steve", last_name="Lorello")
12191213
await m.save()
1220-
1214+
print(m.age)
12211215
assert m.age == 18
1222-
assert m.is_new is True
1223-
assert m.is_newer is True
1224-
assert m.is_great is True
12251216

1226-
rematerialized = await GreatGrandChild.find(GreatGrandChild.pk == m.pk).first()
1217+
rematerialized = await Child.find(Child.pk == m.pk).first()
12271218

12281219
assert rematerialized.age == 18
12291220
assert rematerialized.age != 19
12301221
assert rematerialized.bio is None
1231-
assert rematerialized.is_new is True
1232-
assert rematerialized.is_newer is True
1233-
assert rematerialized.is_great is True
1222+
12341223

12351224
@py_test_mark_asyncio
12361225
async def test_merged_model_error():
@@ -1246,4 +1235,3 @@ class Game(JsonModel):
12461235
)
12471236
print(q.query)
12481237
assert q.query == "(@player1_username:{username})| (@player2_username:{username})"
1249-

0 commit comments

Comments
 (0)