Skip to content

Commit 3d94993

Browse files
author
Averchenkov Roman
committed
apply suggestions
1 parent b4817e8 commit 3d94993

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

src/gino/declarative.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ def _init_table(cls, sub_cls):
351351
for k, v in updates.items():
352352
setattr(sub_cls, k, v)
353353

354-
prop_names = []
354+
json_prop_names = []
355355
for each_cls in sub_cls.__mro__[::-1]:
356356
for k, v in each_cls.__dict__.items():
357357
if isinstance(v, json_support.JSONProperty):
358358
if not v.name:
359359
v.name = k
360-
if v.prop_name not in prop_names:
361-
prop_names.append(v.prop_name)
360+
if v.prop_name not in json_prop_names:
361+
json_prop_names.append(v.prop_name)
362362
json_col = getattr(
363363
sub_cls.__dict__.get(v.prop_name), "column", None
364364
)
@@ -371,7 +371,7 @@ def _init_table(cls, sub_cls):
371371
type(v).__name__, v.name, v.prop_name,
372372
)
373373
)
374-
sub_cls._prop_names = prop_names
374+
sub_cls.__json_prop_names__ = json_prop_names
375375
return rv
376376

377377

src/gino/json_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_profile(self, instance):
5555
props = type(instance).__dict__
5656
instance.__profile__ = {}
5757
profiles = {}
58-
for prop_name in getattr(instance, "_prop_names", []):
58+
for prop_name in getattr(instance, "__json_prop_names__", []):
5959
profiles.update(getattr(instance, prop_name, None) or {})
6060
for key, value in profiles.items():
6161
if key not in props:

tests/test_json.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ async def test_crud(bind):
2424

2525
now = datetime.utcnow()
2626
now_str = now.strftime(DATETIME_FORMAT)
27-
u = await User.create(nickname="fantix", birthday=now, bio="I code in Python and more.")
27+
u = await User.create(
28+
nickname="fantix", birthday=now, bio="I code in Python and more."
29+
)
2830
u.age += 1
2931
assert await u.query.gino.model(None).first() == (
3032
1,
@@ -69,7 +71,12 @@ async def test_crud(bind):
6971
# Reload and test updating both JSON and regular property
7072
u = await User.get(u.id)
7173
await u.update(
72-
age=User.age - 2, balance=200.15, realname="daisy", nickname="daisy.nick", height=185, weight=75
74+
age=User.age - 2,
75+
balance=200.15,
76+
realname="daisy",
77+
nickname="daisy.nick",
78+
height=185,
79+
weight=75,
7380
).apply()
7481
data = await u.query.gino.model(None).first()
7582
assert await u.query.gino.model(None).first() == (
@@ -91,7 +98,7 @@ async def test_crud(bind):
9198
team_id=None,
9299
bio="I code in Python and more.",
93100
height=185,
94-
weight=75
101+
weight=75,
95102
)
96103

97104
# Deleting property doesn't affect database
@@ -168,10 +175,10 @@ class PropsTest(db.Model):
168175

169176
parameter = db.Column(JSONB(), nullable=False, server_default="{}")
170177

171-
raw_param = db.JSONProperty(prop_name='parameter')
172-
bool_param = db.BooleanProperty(prop_name='parameter')
173-
obj_param = db.ObjectProperty(prop_name='parameter')
174-
arr_param = db.ArrayProperty(prop_name='parameter')
178+
raw_param = db.JSONProperty(prop_name="parameter")
179+
bool_param = db.BooleanProperty(prop_name="parameter")
180+
obj_param = db.ObjectProperty(prop_name="parameter")
181+
arr_param = db.ArrayProperty(prop_name="parameter")
175182

176183
await PropsTest.gino.create()
177184
try:
@@ -180,7 +187,6 @@ class PropsTest(db.Model):
180187
bool=True,
181188
obj=dict(x=1, y=2),
182189
arr=[3, 4, 5, 6],
183-
184190
raw_param=dict(a=[3, 4]),
185191
bool_param=False,
186192
obj_param=dict(x=3, y=4),
@@ -191,10 +197,22 @@ class PropsTest(db.Model):
191197
assert t.arr[-1] == 6
192198
assert t.arr_param[-1] == 10
193199
data = await db.select(
194-
[PropsTest.profile, PropsTest.parameter, PropsTest.raw, PropsTest.bool, PropsTest.obj_param]
200+
[
201+
PropsTest.profile,
202+
PropsTest.parameter,
203+
PropsTest.raw,
204+
PropsTest.bool,
205+
PropsTest.obj_param,
206+
]
195207
).gino.first()
196208
assert await db.select(
197-
[PropsTest.profile, PropsTest.parameter, PropsTest.raw, PropsTest.bool, PropsTest.obj_param]
209+
[
210+
PropsTest.profile,
211+
PropsTest.parameter,
212+
PropsTest.raw,
213+
PropsTest.bool,
214+
PropsTest.obj_param,
215+
]
198216
).gino.first() == (
199217
{
200218
"arr": [3, 4, 5, 6],

0 commit comments

Comments
 (0)