-
Notifications
You must be signed in to change notification settings - Fork 73
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
Changes to support bidirectional consent #5118
Changes to support bidirectional consent #5118
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Test summaryRun details
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5118 +/- ##
==========================================
- Coverage 86.55% 86.52% -0.03%
==========================================
Files 357 359 +2
Lines 22340 22470 +130
Branches 2957 2978 +21
==========================================
+ Hits 19336 19443 +107
- Misses 2480 2494 +14
- Partials 524 533 +9 ☔ View full report in Codecov by Sentry. |
src/fides/api/alembic/migrations/versions/d69cf8f82a58_add_consent_automation_tables.py
Show resolved
Hide resolved
…hema to prevent calling from_orm during payload validation
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.
Overall a very clean implementation @galvana , well done! Overall the functionality works as expected, but just a couple items to clarify and some additional tests for some of the DB functionality. Thanks!
["privacynotice.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["parent_id"], ["plus_consentable_item.id"], ondelete="CASCADE" |
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.
Can we add a test for this cascade functionality, too?
sa.ForeignKeyConstraint( | ||
["consent_automation_id"], | ||
["plus_consent_automation.id"], | ||
ondelete="CASCADE", |
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.
Can we add a test for this cascade functionality?
notice_id=item_data.get("notice_id"), | ||
) | ||
db.add(item) | ||
# flush to the DB so we can get the auto-generated ID for this item |
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.
can you explain how flush works? I haven't had to use this manually before
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.
flush()
lets you push changes to the database without committing the transaction. In this case, we just called db.add(item)
to add a new ConsentableItem
to this current DB session, but if we want to get the ID for that new item, we can call flush()
and this would be executed in the current transaction
2024-07-30 11:09:21 2024-07-30 18:09:21.081 UTC [148] LOG: statement: INSERT INTO plus_consentable_item (id, consent_automation_id, external_id, parent_id, notice_id, type, name) VALUES ('plu_16815018-1e85-45f8-beb0-8c1a7998412f', 'plu_6f56003c-610e-4196-8e21-ed6815be9bc8', '1', 'plu_fc600d19-7101-4db4-b148-1849c667fae3', NULL, 'Message type', 'Weekly Ads')
So it's enough for us to get an ID without us having to commit the current transaction. If any exceptions occur during later in the code (after flush()
), we can still roll everything back as if nothing happened.
parent: "RelationshipProperty[Optional[ConsentableItem]]" = relationship( | ||
"ConsentableItem", | ||
back_populates="children", | ||
remote_side=[id], |
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.
what is remote_side
?
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.
It's needed for self-referential relationships like what we're doing here with ConsentableItem
. There's an in-depth explanation here but the way I was able to reason about it was that it's telling SQLAlchemy which side of the relationship is the "parent" or "one" side of a one-to-many relationship. As an example, one ConsentableItem
can have an id
of 1, but many ConsentableItems
can have their parent_id
be 1, so id
would be the "remote_side".
.filter(ConsentableItem.consent_automation_id == consent_automation.id) | ||
.all() | ||
) | ||
assert len(consentable_items) == 0 |
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.
awesome, thanks!
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.
thanks for adding those tests @galvana !
Oh, and can we add a CHANGELOG entry here too? |
Test summaryRun details
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud |
Closes PROD-2343
Description Of Changes
Core changes to support the
PUT
andGET
/consentable-items
endpoints in Fidesplus.Code Changes
plus_consent_automation
andplus_consentable_item
tablesget_consentable_items
,update_consent
,process_consent_webhook
)Steps to Confirm
Pre-Merge Checklist
CHANGELOG.md
main
downgrade()
migration is correct and works