Skip to content

Commit

Permalink
Updated FinancialInstitutionWithRelationsDto and institution_repo
Browse files Browse the repository at this point in the history
Fixed FinancialInstitutionWithRelationsDto to container a list of sbl_institution_types
Updated institution_repo to correct merge issues with main
  • Loading branch information
jcadam14 committed Jan 9, 2024
1 parent 1b205e6 commit 8c63f6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/entities/models/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Config:
class FinancialInstitutionWithRelationsDto(FinancialInstitutionDto):
primary_federal_regulator: FederalRegulatorDto | None = None
hmda_institution_type: InstitutionTypeDto | None = None
sbl_institution_type: InstitutionTypeDto | None = None
sbl_institution_types: List[InstitutionTypeDto] = []
hq_address_state: AddressStateDto
domains: List[FinancialInsitutionDomainDto] = []

Expand Down
13 changes: 3 additions & 10 deletions src/entities/repos/institutions_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ async def get_federal_regulators(session: AsyncSession) -> List[FederalRegulator

async def upsert_institution(session: AsyncSession, fi: FinancialInstitutionDto) -> FinancialInstitutionDao:
async with session.begin():
stmt = select(FinancialInstitutionDao).filter(FinancialInstitutionDao.lei == fi.lei)
res = await session.execute(stmt)
db_fi = res.scalar_one_or_none()
fi_data = fi.__dict__.copy()
fi_data.pop("_sa_instance_state", None)

Expand All @@ -85,13 +82,9 @@ async def upsert_institution(session: AsyncSession, fi: FinancialInstitutionDto)
fi_data["sbl_institution_types"] = sbl_types.all()
del fi_data["sbl_institution_type_ids"]

if db_fi is None:
db_fi = FinancialInstitutionDao(**fi_data)
session.add(db_fi)
else:
for key, value in fi_data.items():
setattr(db_fi, key, value)
await session.commit()
db_fi = await session.merge(FinancialInstitutionDao(**fi_data))
await session.flush([db_fi])
await session.refresh(db_fi)
return db_fi


Expand Down

0 comments on commit 8c63f6d

Please sign in to comment.