Skip to content

getAffiliation always returns None #65

Closed
@Castronova

Description

@Castronova

There is a bug in readService.getAffiliation that causes it to always returns None.

q = self._session.query(Affiliations)
if ids: q = q.filter(Affiliations.AffiliationID.in_(ids))
if orgcode: q = q.filter(Organizations.OrganizationCode.ilike(orgcode))
if personfirst: q = q.filter(People.PersonFirstName.ilike(personfirst))
if personlast: q = q.filter(People.PersonLastName.ilike(personlast)).first()
try:
    return q.all()
except:
    return None

to fix, change the PersonLastName filter to:

if personlast: q = q.filter(People.PersonLastName.ilike(personlast))

Additionally, the following exception is raised AttributeError: 'Affiliations' object has no attribute 'all', but the user is not informed because all of the api functions return None without any error message. Is there a reason for this? The function above could be rewritten as:

q = self._session.query(Affiliations)
if ids: q = q.filter(Affiliations.AffiliationID.in_(ids))
if orgcode: q = q.filter(Organizations.OrganizationCode.ilike(orgcode))
if personfirst: q = q.filter(People.PersonFirstName.ilike(personfirst))
if personlast: q = q.filter(People.PersonLastName.ilike(personlast))

try:
    res = q.all() or None
except AttributeError as e:
    print(e)
    res = None
return res

I suggest that someone update/implement unit tests for all api functions to make sure they work as expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions