Skip to content

Commit

Permalink
CRF #600
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Dec 26, 2019
1 parent a63b2af commit 6a61f0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Contributors
* Jim O'Brien <[email protected]>
* Ilaï Deutel <[email protected]>
* Roald Storm <[email protected]>
* Tiago Requeijo <[email protected]>


Special thanks to my wife Daisy and her outsourcing company `DecentFoX Studio`_,
Expand Down
3 changes: 1 addition & 2 deletions src/gino/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,7 @@ def lookup(self):
"""
exps = []
for c in self.__table__.primary_key.columns:
exps.append(c == getattr(self,
self._column_name_map.invert_get(c.name)))
exps.append(c == getattr(self, self._column_name_map.invert_get(c.name)))
if exps:
return sa.and_(*exps)
else:
Expand Down
32 changes: 21 additions & 11 deletions tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,34 +288,44 @@ class Game(db.Model):


async def test_lookup_custom_name(bind):
from gino.exceptions import NoSuchRowError

class ModelWithCustomColumnNames(db.Model):
__tablename__ = 'gino_test_custom_column_names'
__tablename__ = "gino_test_custom_column_names"

id = db.Column('other', db.Integer(), primary_key=True)
id = db.Column("other", db.Integer(), primary_key=True)
field = db.Column(db.Text())

await ModelWithCustomColumnNames.gino.create()

try:
# create
m1 = await ModelWithCustomColumnNames.create(id=1, field='A')
m2 = await ModelWithCustomColumnNames.create(id=2, field='B')
m1 = await ModelWithCustomColumnNames.create(id=1, field="A")
m2 = await ModelWithCustomColumnNames.create(id=2, field="B")

# update
uq = m1.update(field='C')
uq = m1.update(field="C")
await uq.apply()

# lookup
assert set(tuple(x) for x in await ModelWithCustomColumnNames.select('id').gino.all()) == {(1,), (2,)}
assert set(
tuple(x) for x in await ModelWithCustomColumnNames.select("id").gino.all()
) == {(1,), (2,)}
assert (await ModelWithCustomColumnNames.get(2)).field == "B"
assert (await ModelWithCustomColumnNames.get(1)).field == "C"
assert await ModelWithCustomColumnNames.get(3) is None

# delete
assert (await ModelWithCustomColumnNames.delete.where(ModelWithCustomColumnNames.id == 3).gino.status())[0][-1] == '0'
assert (await ModelWithCustomColumnNames.delete.where(ModelWithCustomColumnNames.id == 2).gino.status())[0][-1] == '1'
assert set(tuple(x) for x in await ModelWithCustomColumnNames.select('id').gino.all()) == {(1,)}
assert (
await ModelWithCustomColumnNames.delete.where(
ModelWithCustomColumnNames.id == 3
).gino.status()
)[0][-1] == "0"
assert (
await ModelWithCustomColumnNames.delete.where(
ModelWithCustomColumnNames.id == 2
).gino.status()
)[0][-1] == "1"
assert set(
tuple(x) for x in await ModelWithCustomColumnNames.select("id").gino.all()
) == {(1,)}
finally:
await ModelWithCustomColumnNames.gino.drop()

0 comments on commit 6a61f0c

Please sign in to comment.