Skip to content

Commit 6a61f0c

Browse files
committed
CRF #600
1 parent a63b2af commit 6a61f0c

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Contributors
4040
* Jim O'Brien <[email protected]>
4141
* Ilaï Deutel <[email protected]>
4242
* Roald Storm <[email protected]>
43+
* Tiago Requeijo <[email protected]>
4344

4445

4546
Special thanks to my wife Daisy and her outsourcing company `DecentFoX Studio`_,

src/gino/crud.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ def lookup(self):
579579
"""
580580
exps = []
581581
for c in self.__table__.primary_key.columns:
582-
exps.append(c == getattr(self,
583-
self._column_name_map.invert_get(c.name)))
582+
exps.append(c == getattr(self, self._column_name_map.invert_get(c.name)))
584583
if exps:
585584
return sa.and_(*exps)
586585
else:

tests/test_crud.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,34 +288,44 @@ class Game(db.Model):
288288

289289

290290
async def test_lookup_custom_name(bind):
291-
from gino.exceptions import NoSuchRowError
292-
293291
class ModelWithCustomColumnNames(db.Model):
294-
__tablename__ = 'gino_test_custom_column_names'
292+
__tablename__ = "gino_test_custom_column_names"
295293

296-
id = db.Column('other', db.Integer(), primary_key=True)
294+
id = db.Column("other", db.Integer(), primary_key=True)
297295
field = db.Column(db.Text())
298296

299297
await ModelWithCustomColumnNames.gino.create()
300298

301299
try:
302300
# create
303-
m1 = await ModelWithCustomColumnNames.create(id=1, field='A')
304-
m2 = await ModelWithCustomColumnNames.create(id=2, field='B')
301+
m1 = await ModelWithCustomColumnNames.create(id=1, field="A")
302+
m2 = await ModelWithCustomColumnNames.create(id=2, field="B")
305303

306304
# update
307-
uq = m1.update(field='C')
305+
uq = m1.update(field="C")
308306
await uq.apply()
309307

310308
# lookup
311-
assert set(tuple(x) for x in await ModelWithCustomColumnNames.select('id').gino.all()) == {(1,), (2,)}
309+
assert set(
310+
tuple(x) for x in await ModelWithCustomColumnNames.select("id").gino.all()
311+
) == {(1,), (2,)}
312312
assert (await ModelWithCustomColumnNames.get(2)).field == "B"
313313
assert (await ModelWithCustomColumnNames.get(1)).field == "C"
314314
assert await ModelWithCustomColumnNames.get(3) is None
315315

316316
# delete
317-
assert (await ModelWithCustomColumnNames.delete.where(ModelWithCustomColumnNames.id == 3).gino.status())[0][-1] == '0'
318-
assert (await ModelWithCustomColumnNames.delete.where(ModelWithCustomColumnNames.id == 2).gino.status())[0][-1] == '1'
319-
assert set(tuple(x) for x in await ModelWithCustomColumnNames.select('id').gino.all()) == {(1,)}
317+
assert (
318+
await ModelWithCustomColumnNames.delete.where(
319+
ModelWithCustomColumnNames.id == 3
320+
).gino.status()
321+
)[0][-1] == "0"
322+
assert (
323+
await ModelWithCustomColumnNames.delete.where(
324+
ModelWithCustomColumnNames.id == 2
325+
).gino.status()
326+
)[0][-1] == "1"
327+
assert set(
328+
tuple(x) for x in await ModelWithCustomColumnNames.select("id").gino.all()
329+
) == {(1,)}
320330
finally:
321331
await ModelWithCustomColumnNames.gino.drop()

0 commit comments

Comments
 (0)