Skip to content

Commit

Permalink
Fixed pg8000 integer field issue. (#3035)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwei1018 authored Sep 21, 2024
2 parents e37160c + 80f8a4a commit 2fb4a02
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auth-web-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
branches:
- main
- feature*
paths:
- "auth-web/**"
paths:
- "auth-web/**"
workflow_dispatch:
inputs:
target:
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/account_login_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ class AccountLoginOptions(Versioned, BaseModel): # pylint: disable=too-few-publ
@classmethod
def find_active_by_org_id(cls, account_id: int):
"""Find an account setting instance that matches the provided org_id."""
return cls.query.filter_by(org_id=account_id).filter_by(is_active=True).first()
return cls.query.filter_by(org_id=int(account_id or -1)).filter_by(is_active=True).first()
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/affidavit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def find_by_org_id(cls, org_id: int, filtered_affidavit_statuses=None):
@classmethod
def find_pending_by_user_id(cls, user_id: int):
"""Find pending affidavit by user id."""
return cls.query.filter_by(user_id=user_id, status_code=AffidavitStatus.PENDING.value).one_or_none()
return cls.query.filter_by(user_id=int(user_id or -1), status_code=AffidavitStatus.PENDING.value).one_or_none()

@classmethod
def find_approved_by_user_id(cls, user_id: int):
"""Find pending affidavit by user id."""
return cls.query.filter_by(user_id=user_id, status_code=AffidavitStatus.APPROVED.value).one_or_none()
return cls.query.filter_by(user_id=int(user_id or -1), status_code=AffidavitStatus.APPROVED.value).one_or_none()

@classmethod
def find_effective_by_user_guid(cls, user_guid: str, status: str = None):
Expand Down
10 changes: 5 additions & 5 deletions auth-api/src/auth_api/models/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ def filter_environment(cls, environment: str):
@classmethod
def find_affiliation_by_org_and_entity_ids(cls, org_id: int, entity_id: int, environment) -> Affiliation:
"""Return an affiliation for the provided org and entity ids."""
query = cls.filter_environment(environment).filter_by(org_id=org_id, entity_id=entity_id)
query = cls.filter_environment(environment).filter_by(org_id=int(org_id or -1), entity_id=int(entity_id or -1))
return query.one_or_none()

@classmethod
def find_affiliations_by_entity_id(cls, entity_id: int, environment) -> List[Affiliation]:
"""Return affiliations for the provided entity id."""
return cls.filter_environment(environment).filter_by(entity_id=entity_id).all()
return cls.filter_environment(environment).filter_by(entity_id=int(entity_id or -1)).all()

@classmethod
def find_affiliation_by_ids(cls, org_id: int, affiliation_id: int) -> Affiliation:
"""Return the first Affiliation with the provided ids."""
return cls.query.filter_by(org_id=org_id).filter_by(id=affiliation_id).one_or_none()
return cls.query.filter_by(org_id=int(org_id or -1)).filter_by(id=int(affiliation_id or -1)).one_or_none()

@classmethod
def find_affiliations_by_org_id(cls, org_id: int, environment: str) -> List[Affiliation]:
Expand All @@ -81,7 +81,7 @@ def find_affiliations_by_org_id(cls, org_id: int, environment: str) -> List[Affi
EntityModel.business_identifier, EntityModel.corp_type_code
)
)
.filter(Affiliation.org_id == org_id)
.filter(Affiliation.org_id == int(org_id or -1))
)
if environment:
query = query.filter(Affiliation.environment == environment)
Expand Down Expand Up @@ -112,7 +112,7 @@ def find_affiliation_by_org_id_and_business_identifier(
EntityModel.business_identifier, EntityModel.corp_type_code
)
)
.filter(Affiliation.org_id == org_id)
.filter(Affiliation.org_id == int(org_id or -1))
.filter(EntityModel.business_identifier == business_identifier)
)
if environment:
Expand Down
33 changes: 12 additions & 21 deletions auth-api/src/auth_api/models/affiliation_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,39 +118,27 @@ def filter_by(cls, search_filter: AffiliationInvitationSearch, query=None) -> li
results = db.session.query(AffiliationInvitation)

if search_filter.from_org_id:
results = results.filter(
AffiliationInvitation.from_org_id.cast(Integer) == search_filter.from_org_id.cast(Integer)
)
results = results.filter(AffiliationInvitation.from_org_id == int(search_filter.from_org_id))
filter_set = True

if search_filter.to_org_id:
results = results.filter(
AffiliationInvitation.to_org_id.cast(Integer) == search_filter.to_org_id.cast(Integer)
)
results = results.filter(AffiliationInvitation.to_org_id == int(search_filter.to_org_id))
filter_set = True

if search_filter.sender_id:
results = results.filter(
AffiliationInvitation.sender_id.cast(Integer) == search_filter.sender_id.cast(Integer)
)
results = results.filter(AffiliationInvitation.sender_id == int(search_filter.sender_id))
filter_set = True

if search_filter.approver_id:
results = results.filter(
AffiliationInvitation.approver_id.cast(Integer) == search_filter.approver_id.cast(Integer)
)
results = results.filter(AffiliationInvitation.approver_id == int(search_filter.approver_id))
filter_set = True

if search_filter.entity_id:
results = results.filter(
AffiliationInvitation.entity_id.cast(Integer) == search_filter.entity_id.cast(Integer)
)
results = results.filter(AffiliationInvitation.entity_id == int(search_filter.entity_id))
filter_set = True

if search_filter.affiliation_id:
results = results.filter(
AffiliationInvitation.affiliation_id.cast(Integer) == search_filter.affiliation_id.cast(Integer)
)
results = results.filter(AffiliationInvitation.affiliation_id == int(search_filter.affiliation_id))
filter_set = True

if search_filter.status_codes:
Expand All @@ -173,7 +161,7 @@ def filter_by(cls, search_filter: AffiliationInvitationSearch, query=None) -> li
@classmethod
def find_invitation_by_id(cls, invitation_id: int):
"""Find an affiliation invitation record that matches the id."""
return cls.query.filter_by(id=invitation_id).first()
return cls.query.filter_by(id=int(invitation_id or -1)).first()

@classmethod
def find_invitations_from_org(cls, org_id: int, status=None):
Expand All @@ -196,7 +184,7 @@ def find_invitations_by_entity(cls, entity_id: int, status=None):
@classmethod
def find_invitations_by_affiliation(cls, affiliation_id: int):
"""Find all affiliation invitations associated to an affiliation."""
return cls.query.filter_by(affiliation_id=affiliation_id).all()
return cls.query.filter_by(affiliation_id=int(affiliation_id or -1)).all()

@staticmethod
def find_invitations_by_org_entity_ids(from_org_id: int, entity_id: int):
Expand Down Expand Up @@ -232,7 +220,10 @@ def set_status(self, new_status_code: str):
def find_all_related_to_org(cls, org_id: int, search_filter=AffiliationInvitationSearch()):
"""Return all affiliation invitations that are related to the org (from org or to org) filtered by statuses."""
query = db.session.query(AffiliationInvitation).filter(
or_(AffiliationInvitation.to_org_id == int(org_id), AffiliationInvitation.from_org_id == int(org_id))
or_(
AffiliationInvitation.to_org_id == int(org_id or -1),
AffiliationInvitation.from_org_id == int(org_id or -1),
)
)

return cls.filter_by(search_filter=search_filter, query=query)
8 changes: 4 additions & 4 deletions auth-api/src/auth_api/models/contact_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ class ContactLink(Versioned, BaseModel): # pylint: disable=too-few-public-metho
@classmethod
def find_by_entity_id(cls, entity_id: int):
"""Return the first contact link with the provided entity id."""
return cls.query.filter_by(entity_id=entity_id).first()
return cls.query.filter_by(entity_id=int(entity_id or -1)).first()

@classmethod
def find_by_user_id(cls, user_id: int):
"""Return the first contact link with the provided user id."""
return cls.query.filter_by(user_id=user_id).first()
return cls.query.filter_by(user_id=int(user_id or -1)).first()

@classmethod
def find_by_org_id(cls, org_id: int):
"""Return the first contact link with the provided org id."""
return cls.query.filter_by(org_id=org_id).first()
return cls.query.filter_by(org_id=int(org_id or -1)).first()

@classmethod
def find_by_affidavit_id(cls, affidavit_id: int):
"""Return the first contact link with the provided affidavit id."""
return cls.query.filter_by(affidavit_id=affidavit_id).one_or_none()
return cls.query.filter_by(affidavit_id=int(affidavit_id or -1)).one_or_none()

def has_links(self):
"""Check whether there are any remaining links for this contact."""
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_from_dict(cls, entity_info: dict):
@classmethod
def find_by_entity_id(cls, entity_id: int):
"""Find an Entity instance that matches the provided id."""
return cls.query.filter_by(id=entity_id).first()
return cls.query.filter_by(id=int(entity_id or -1)).first()

def reset(self):
"""Reset an Entity back to init state."""
Expand Down
6 changes: 3 additions & 3 deletions auth-api/src/auth_api/models/invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ def create_from_dict(cls, invitation_info: dict, user_id: int, invitation_type):
@classmethod
def find_invitations_by_user(cls, user_id: int):
"""Find all invitation sent by the given user."""
return cls.query.filter_by(sender_id=user_id).all()
return cls.query.filter_by(sender_id=int(user_id or -1)).all()

@classmethod
def find_invitation_by_id(cls, invitation_id: int):
"""Find an invitation record that matches the id."""
return cls.query.filter_by(id=invitation_id).first()
return cls.query.filter_by(id=int(invitation_id or -1)).first()

@classmethod
def find_invitations_by_org(cls, org_id: int, status=None):
"""Find all invitations sent for specific org filtered by status."""
results = cls.query.filter(Invitation.membership.any(InvitationMembership.org_id.cast(Integer) == org_id))
results = cls.query.filter(Invitation.membership.any(InvitationMembership.org_id == int(org_id or -1)))
return results.filter(Invitation.status == status.value).all() if status else results.all()

@staticmethod
Expand Down
32 changes: 16 additions & 16 deletions auth-api/src/auth_api/models/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def __init__(self, **kwargs): # pylint: disable=super-init-not-called
@classmethod
def find_membership_by_id(cls, membership_id: int) -> Membership:
"""Find the first membership with the given id and return it."""
return cls.query.filter_by(id=membership_id).first()
return cls.query.filter_by(id=int(membership_id or -1)).first()

@classmethod
def find_members_by_org_id(cls, org_id: int) -> List[Membership]:
"""Return all members of the org with a status."""
return cls.query.filter_by(org_id=org_id).all()
return cls.query.filter_by(org_id=int(org_id or -1)).all()

@classmethod
def get_pending_members_count_by_org_id(cls, org_id: int) -> int:
Expand All @@ -84,7 +84,7 @@ def get_pending_members_count_by_org_id(cls, org_id: int) -> int:
db.session.query(Membership)
.filter(and_(Membership.status == Status.PENDING_APPROVAL.value))
.join(OrgModel)
.filter(OrgModel.id == org_id)
.filter(OrgModel.id == int(org_id or -1))
)
# pylint:disable=not-callable
count_q = query.statement.with_only_columns(func.count(), maintain_column_froms=True).order_by(None)
Expand All @@ -100,7 +100,7 @@ def find_members_by_org_id_by_status_by_roles(
db.session.query(Membership)
.filter(and_(Membership.status == status, Membership.membership_type_code.in_(roles)))
.join(OrgModel)
.filter(OrgModel.id == org_id)
.filter(OrgModel.id == int(org_id or -1))
.all()
)

Expand All @@ -109,7 +109,7 @@ def find_orgs_for_user(cls, user_id: int, valid_statuses=VALID_STATUSES) -> List
"""Find the orgs for a user."""
records = (
cls.query.join(OrgModel)
.filter(cls.user_id == user_id)
.filter(cls.user_id == int(user_id or -1))
.filter(cls.status.in_(valid_statuses))
.filter(OrgModel.status_code.in_(VALID_ORG_STATUSES))
.all()
Expand All @@ -122,7 +122,7 @@ def find_active_staff_org_memberships_for_user(cls, user_id: int) -> List[Member
"""Find staff orgs memberships for a user."""
return (
cls.query.join(OrgModel)
.filter(cls.user_id == user_id)
.filter(cls.user_id == int(user_id or -1))
.filter(cls.status == Status.ACTIVE.value)
.filter(OrgModel.status_code.in_(VALID_ORG_STATUSES))
.filter(OrgModel.type_code == OrgType.STAFF.value)
Expand Down Expand Up @@ -163,23 +163,23 @@ def find_membership_by_user_and_org(cls, user_id: int, org_id: int) -> Membershi
@classmethod
def find_membership_by_userid(cls, user_id: int) -> Membership:
"""Get the membership for the specified user."""
records = cls.query.filter(cls.user_id == user_id).order_by(desc(Membership.created)).first()
records = cls.query.filter(cls.user_id == int(user_id or -1)).order_by(desc(Membership.created)).first()

return records

@classmethod
def find_memberships_by_user_ids(cls, user_id: int) -> List[Membership]:
"""Get the memberships for the specified user ids."""
records = cls.query.filter(cls.user_id == user_id).order_by(desc(Membership.created)).all()
records = cls.query.filter(cls.user_id == int(user_id or -1)).order_by(desc(Membership.created)).all()

return records

@classmethod
def find_membership_by_user_and_org_all_status(cls, user_id: int, org_id: int) -> Membership:
"""Get the membership for the specified user and org with all membership statuses."""
records = (
cls.query.filter(cls.user_id == user_id)
.filter(cls.org_id == org_id)
cls.query.filter(cls.user_id == int(user_id or -1))
.filter(cls.org_id == int(org_id or -1))
.order_by(desc(Membership.created))
.first()
)
Expand All @@ -193,13 +193,13 @@ def get_count_active_owner_org_id(cls, org_id: int) -> int:
db.session.query(Membership)
.filter(
and_(
Membership.org_id == org_id,
Membership.org_id == int(org_id or -1),
Membership.status == Status.ACTIVE.value,
Membership.membership_type_code == ADMIN,
)
)
.join(OrgModel)
.filter(OrgModel.id == org_id)
.filter(OrgModel.id == int(org_id or -1))
)

# pylint:disable=not-callable
Expand All @@ -214,14 +214,14 @@ def check_if_active_admin_or_owner_org_id(cls, org_id: int, user_id: int) -> int
db.session.query(Membership)
.filter(
and_(
Membership.user_id == user_id,
Membership.org_id == org_id,
Membership.user_id == int(user_id or -1),
Membership.org_id == int(org_id or -1),
Membership.status == Status.ACTIVE.value,
Membership.membership_type_code.in_((ADMIN, COORDINATOR)),
)
)
.join(OrgModel)
.filter(OrgModel.id == org_id)
.filter(OrgModel.id == int(org_id or -1))
)
# pylint:disable=not-callable
count_q = query.statement.with_only_columns(func.count(), maintain_column_froms=True).order_by(None)
Expand All @@ -235,7 +235,7 @@ def check_if_sbc_staff(cls, user_id: int) -> bool:
db.session.query(Membership)
.filter(
and_(
Membership.user_id == user_id,
Membership.user_id == int(user_id or -1),
Membership.status == Status.ACTIVE.value,
Membership.org.has(OrgModel.type_code == OrgType.SBC_STAFF.value),
)
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def find_by_org_uuid(cls, org_uuid):
@classmethod
def find_by_org_id(cls, org_id: int):
"""Find an Org instance that matches the provided id."""
return cls.query.filter_by(id=org_id).first()
return cls.query.filter_by(id=int(org_id or -1)).first()

@classmethod
def find_by_bcol_id(cls, bcol_account_id):
Expand Down
6 changes: 4 additions & 2 deletions auth-api/src/auth_api/models/org_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ class OrgSettings(
@classmethod
def get_org_settings(cls, org_id: int):
"""Return the default status code for an Org."""
return cls.query.filter_by(org_id=org_id).all()
return cls.query.filter_by(org_id=int(org_id or -1)).all()

@classmethod
def is_admin_auto_approved_invitees(cls, org_id: int):
"""Return the default status code for an Org."""
org_model = cls.query.filter_by(org_id=org_id, setting="ADMIN_AUTO_APPROVAL_FOR_MEMBER_ACCEPTANCE").first()
org_model = cls.query.filter_by(
org_id=int(org_id or -1), setting="ADMIN_AUTO_APPROVAL_FOR_MEMBER_ACCEPTANCE"
).first()
if org_model is not None:
return org_model.enabled
return False
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/pubsub_message_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class PubSubMessageProcessing(db.Model):
processed = Column(DateTime, nullable=True)

@classmethod
def find_by_id(cls, identifier):
def find_by_id(cls, identifier: int):
"""Find a pubsub message processing by id."""
return cls.query.filter_by(id=identifier).one_or_none()
return cls.query.filter_by(id=int(identifier)).one_or_none()

@classmethod
def find_by_cloud_event_id_and_type(cls, cloud_event_id, message_type):
Expand Down
8 changes: 5 additions & 3 deletions auth-api/src/auth_api/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def fetch_tasks(cls, task_search: TaskSearch):
@classmethod
def find_by_task_id(cls, task_id: int):
"""Find a task instance that matches the provided id."""
return db.session.query(Task).filter_by(id=task_id).first()
return db.session.query(Task).filter_by(id=int(task_id or -1)).first()

@classmethod
def find_by_task_relationship_id(
Expand All @@ -117,7 +117,9 @@ def find_by_task_for_account(cls, org_id: int, status):
"""Find a task instance that matches the provided id."""
return (
db.session.query(Task)
.filter_by(relationship_id=org_id, relationship_type=TaskRelationshipType.ORG.value, status=status)
.filter_by(
relationship_id=int(org_id or -1), relationship_type=TaskRelationshipType.ORG.value, status=status
)
.first()
)

Expand All @@ -126,7 +128,7 @@ def find_by_user_and_status(cls, org_id: int, status):
"""Find a task instance that matches the provided id."""
return (
db.session.query(Task)
.filter_by(account_id=org_id, relationship_type=TaskRelationshipType.USER.value, status=status)
.filter_by(account_id=int(org_id or -1), relationship_type=TaskRelationshipType.USER.value, status=status)
.first()
)

Expand Down
Loading

0 comments on commit 2fb4a02

Please sign in to comment.