-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
68 update institutions table and daos institution type fields #75
68 update institutions table and daos institution type fields #75
Conversation
…ndpoint Adds endpoints for getting address-states and regulators Adds institution repo get_ functions for the above Let commented out code in for specific Dtos in case the general approach isn't desired
Changed the FI DTO to have sbl_institution_type_ids (instead of id) and use a list Changed the FI DAO to have sbl_institution_type_ids and sbl_institution_types, both of which are now lists Changed the FI DAO sbl_institution_type_ids to be an AssociationProxy (view) based on the sbl_institution_types Created an fi_to_type_mapping table that holds the relationship between FI sbl_institution_types and the slb_institution_type table entries Updated the institution_repo fi upsert function to look for incoming DTO sbl_institution_type_ids, and retrieve the corresponding SBLInstitutionTypeDao entries. They are then associated with the fi_data before being inserted/updated (which populates the new mapping table) Updated the pytests to work with this new concept of lists, especially the test_add_institution repo test. Will write a new story for the sbl-project repo once these chanegs are approved and merged in to update the mock_data json
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
…le to drop the sbl_institution_type_id column, and to remove the FK and index. On the downgrade, these are added back in.
…ution-type-fields
# Populate with model objects from SBLInstitutionTypeDao and clear out | ||
# the id field since it's just a view | ||
if "sbl_institution_type_ids" in fi_data: | ||
sbl_type_ids = tuple(fi_data["sbl_institution_type_ids"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this need to be converted to tuple? the ...in_(...)
method just needs an interable, right? so list would be fine?
src/entities/models/dto.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one part that's missing is the updation of the FinancialInstitutionWithRelationsDto
; that should include sbl_institution_types: List[InstitutionTypeDto] = []
@@ -74,6 +74,17 @@ async def upsert_institution(session: AsyncSession, fi: FinancialInstitutionDto) | |||
db_fi = res.scalar_one_or_none() | |||
fi_data = fi.__dict__.copy() | |||
fi_data.pop("_sa_instance_state", None) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the update to the upsert using merge, this is causing the merge conflicts.
I have mine like:
async with session.begin():
fi_data = fi.__dict__.copy()
fi_data.pop("_sa_instance_state", None)
sbl_types = []
if len(fi.sbl_institution_type_ids):
sbl_type_stmt = select(SBLInstitutionTypeDao).filter(
SBLInstitutionTypeDao.id.in_(fi.sbl_institution_type_ids)
)
sbl_types = (await session.scalars(sbl_type_stmt)).all()
del fi_data["sbl_institution_type_ids"]
new_fi = FinancialInstitutionDao(**fi_data)
new_fi.sbl_institution_types.extend(sbl_types)
db_fi = await session.merge(new_fi)
await session.flush([db_fi])
await session.refresh(db_fi)
return db_fi
Fixed FinancialInstitutionWithRelationsDto to container a list of sbl_institution_types Updated institution_repo to correct merge issues with main
…ution-type-fields
SBLInstitutionTypeDao.id.in_(fi_data["sbl_institution_type_ids"]) | ||
) | ||
sbl_types = await session.scalars(sbl_type_stmt) | ||
fi_data["sbl_institution_types"] = sbl_types.all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to keep in mind with not initializing this field out of the if check is any previous relationships would remain the same if the field if not specified. Since this function will only be used by internal processes, I'm ok with this behavior, but it is worth noting this is different from the rest of the fields.
I think we're good to merge now once the commented out code are cleaned up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested wrong, not an issue; we're good to go after clean up.
…fields' of https://github.com/cfpb/regtech-user-fi-management into 68-update-institutions-table-and-daos-institution-type-fields
Closes #68
Changed the FI DTO to have sbl_institution_type_ids (instead of id) and use a list
Changed the FI DAO to have sbl_institution_type_ids and sbl_institution_types, both of which are now lists
Changed the FI DAO sbl_institution_type_ids to be an AssociationProxy (view) based on the sbl_institution_types
Created an fi_to_type_mapping table that holds the relationship between FI sbl_institution_types and the slb_institution_type table entries
Updated the institution_repo fi upsert function to look for incoming DTO sbl_institution_type_ids, and retrieve the corresponding
SBLInstitutionTypeDao entries. They are then associated with the fi_data before being inserted/updated (which populates the new mapping table)
Updated the pytests to work with this new concept of lists, especially the test_add_institution repo test.
Will write a new story for the sbl-project repo once these chanegs are approved and merged in to update the mock_data json