Skip to content
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

Merged

Conversation

jcadam14
Copy link
Contributor

@jcadam14 jcadam14 commented Dec 29, 2023

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

…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
@jcadam14 jcadam14 self-assigned this Dec 29, 2023
@jcadam14 jcadam14 linked an issue Dec 29, 2023 that may be closed by this pull request
Copy link

github-actions bot commented Dec 29, 2023

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/entities/models
  dao.py
  dto.py
  src/entities/repos
  institutions_repo.py
Project Total  

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.
# 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"])
Copy link
Collaborator

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?

@jcadam14 jcadam14 requested a review from lchen-2101 January 8, 2024 20:24
Copy link
Collaborator

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)

Copy link
Collaborator

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
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()
Copy link
Collaborator

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.

Copy link
Collaborator

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.

@jcadam14 jcadam14 merged commit 22dc087 into main Jan 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update institutions table, and dao's institution type fields
2 participants