Skip to content

Commit

Permalink
Fixed pg8000 integer issue. (#3053)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwei1018 authored Sep 27, 2024
2 parents f3882ae + dd6259a commit 7d1cfbc
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/activity_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def fetch_activity_logs_for_account( # pylint: disable=too-many-positional-argu
query = (
db.session.query(ActivityLog, User)
.outerjoin(User, User.id == ActivityLog.actor_id)
.filter(ActivityLog.org_id == org_id)
.filter(ActivityLog.org_id == int(org_id or -1))
.order_by(desc(ActivityLog.created))
)

Expand Down
12 changes: 7 additions & 5 deletions auth-api/src/auth_api/models/affiliation_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,21 @@ def find_invitation_by_id(cls, invitation_id: int):
@classmethod
def find_invitations_from_org(cls, org_id: int, status=None):
"""Find all affiliation invitations sent from a specific org filtered by status."""
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.from_org_id == org_id)
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.from_org_id == int(org_id or -1))
return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all()

@classmethod
def find_invitations_to_org(cls, org_id: int, status=None):
"""Find all affiliation invitations sent to a specific org filtered by status."""
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.to_org_id == org_id)
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.to_org_id == int(org_id or -1))
return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all()

@classmethod
def find_invitations_by_entity(cls, entity_id: int, status=None):
"""Find all affiliation invitations sent for specific entity filtered by status."""
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.entity_id == entity_id)
results = db.session.query(AffiliationInvitation).filter(
AffiliationInvitation.entity_id == int(entity_id or -1)
)
return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all()

@classmethod
Expand All @@ -192,8 +194,8 @@ def find_invitations_by_org_entity_ids(from_org_id: int, entity_id: int):
"""Find all affiliation invitation for org and entity ids."""
return (
db.session.query(AffiliationInvitation)
.filter(AffiliationInvitation.from_org_id == from_org_id)
.filter(AffiliationInvitation.entity_id == entity_id)
.filter(AffiliationInvitation.from_org_id == int(from_org_id or -1))
.filter(AffiliationInvitation.entity_id == int(entity_id or -1))
.filter(
or_(
AffiliationInvitation.invitation_status_code == InvitationStatuses.PENDING.value,
Expand Down
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def find_pending_invitations_by_org(org_id: int):
"""Find all invitations that are not in accepted state."""
return (
db.session.query(Invitation)
.filter(Invitation.membership.any(InvitationMembership.org_id == org_id))
.filter(Invitation.membership.any(InvitationMembership.org_id == int(org_id or -1)))
.filter(Invitation.invitation_status_code != "ACCEPTED")
.all()
)
Expand All @@ -125,7 +125,7 @@ def find_invitations_by_status(user_id: int, status):
"""Find all invitations that are not in accepted state."""
return (
db.session.query(Invitation)
.filter(Invitation.sender_id == user_id)
.filter(Invitation.sender_id == int(user_id or -1))
.filter(Invitation.invitation_status_code == status)
.all()
)
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/product_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def find_by_org_id_product_code(cls, org_id: int, product_code, valid_statuses=V
"""Find an product subscription instance that matches the provided id."""
return cls.query.filter(
and_(
ProductSubscription.org_id == org_id,
ProductSubscription.org_id == int(org_id or -1),
ProductSubscription.product_code == product_code,
ProductSubscription.status_code.in_(valid_statuses),
)
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def find_by_task_relationship_id(
return (
db.session.query(Task)
.filter(
Task.relationship_id == relationship_id,
Task.relationship_id == int(relationship_id or -1),
Task.relationship_type == task_relationship_type,
Task.status == task_status,
)
Expand Down
5 changes: 4 additions & 1 deletion auth-api/src/auth_api/services/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def find_affiliations_by_org_id(org_id, environment=None):
subqueryload(Entity.created_by),
subqueryload(Entity.modified_by),
)
.filter(AffiliationModel.org_id == org_id, Entity.affiliations.any(AffiliationModel.org_id == org_id))
.filter(
AffiliationModel.org_id == int(org_id or -1),
Entity.affiliations.any(AffiliationModel.org_id == int(org_id or -1)),
)
)
if environment:
entities = entities.filter(AffiliationModel.environment == environment)
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/services/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def create_user_and_add_membership(
enabled_in_kc = getattr(existing_kc_user, "enabled", True)
if getattr(user_model, "status", None) == Status.INACTIVE.value and not enabled_in_kc:
membership_model = MembershipModel.find_membership_by_userid(user_model.id)
re_enable_user = membership_model.org_id == org_id
re_enable_user = membership_model.org_id == int(org_id or -1)
if user_model and not re_enable_user:
logger.debug("Existing users found in DB")
users.append(User._get_error_dict(username, Error.USER_ALREADY_EXISTS))
Expand Down

0 comments on commit 7d1cfbc

Please sign in to comment.