Skip to content

Commit 8fc7e8a

Browse files
committed
Modify the db.execute code.
1 parent dfd9c0c commit 8fc7e8a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tests/helpers/util/contributor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sqlalchemy.orm.exc import NoResultFound
2+
from sqlalchemy import select
23
from sqlalchemy.orm import Session
34
from typing import Any
45

@@ -11,7 +12,8 @@ def add_contributor(db: Session, urn: str, model: Any, orcid_id: str, given_name
1112
assert item is not None
1213

1314
try:
14-
contributor = db.query(Contributor).filter(Contributor.orcid_id == orcid_id).one()
15+
# scalar_one(): extract the ORM instance from the result
16+
contributor = db.execute(select(Contributor).where(Contributor.orcid_id == orcid_id)).scalar_one()
1517
except NoResultFound:
1618
contributor = Contributor(orcid_id=orcid_id, given_name=given_name, family_name=family_name)
1719
db.add(contributor)

0 commit comments

Comments
 (0)