-
Notifications
You must be signed in to change notification settings - Fork 72
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
Sync up Database and PreApprovalWebhook/PreApprovalWebhookReply Models #4838
Conversation
…alWebhookReply models: - Add missing preapprovalwebhook.key index in database to match model - Create unique constraint on preapprovalwebhook.name in database to match model - Index the preapprovalwebhookreply.privacy_request_id.privacy_request_id to match the model - Fix/Add FK's on preapprovalwebhookreply privacy_request_id and webhook_id Add further handling if resources get deleted: - Cascade Delete PreApprovalWebhook if the ConnectionConfig is deleted - Set Webhook Id to Null on PreApprovalWebhook Reply if the Webhook itself is deleted to match what happens if Privacy Request is deleted. Make that nullable too.
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Passing run #7495 ↗︎
Details:
Review all test suite changes for PR #4838 ↗︎ |
src/fides/api/alembic/migrations/versions/9e83545ed9b6_pre_approval_webhook_cleanup.py
Show resolved
Hide resolved
# Check if all replies are true | ||
replies_for_privacy_request = PreApprovalWebhookReply.filter( | ||
db=db, | ||
conditions=(PreApprovalWebhookReply.privacy_request_id == privacy_request_id), | ||
).all() | ||
|
||
# Check if all replies are true. Reply ignored if its webhook has since been deleted. | ||
replies_for_privacy_request = ( | ||
db.query(PreApprovalWebhookReply) | ||
.filter( | ||
PreApprovalWebhookReply.privacy_request_id == privacy_request_id, | ||
PreApprovalWebhookReply.webhook_id.isnot(None), | ||
) | ||
.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.
It seems easy to remove a preapproval webhook with the PUT endpoint that removes webhooks that aren't in the request. So if this does happen, replies for a deleted webhook are ignored.
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.
Agree, and this additional check to ignore deleted webhooks is a good one 💯
webhook_id = Column( | ||
String, ForeignKey(PreApprovalWebhook.id_field_path), nullable=False | ||
String, | ||
ForeignKey(PreApprovalWebhook.id_field_path, ondelete="SET NULL"), index=True | ||
) |
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.
New: adding an index on this column (similar to the one on priavcy_request_id because it is commonly queried. Further, I'm setting this field to null in the event the webhook itself is deleted.
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, this makes sense. For future reference, are there any disadvantages to setting an index
on a column at 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.
yes good question, the main disadvantage is that it slows down writes, you definitely don't want to/need to index everything. This seemed like one of the fields that would be queried frequently and this will be a large table.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4838 +/- ##
=======================================
Coverage 86.87% 86.87%
=======================================
Files 345 345
Lines 20855 20856 +1
Branches 2727 2727
=======================================
+ Hits 18118 18119 +1
Misses 2262 2262
Partials 475 475 ☔ View full report in Codecov by Sentry. |
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.
Dawn, your assumptions about the foreign key delete behavior make sense to me. Thanks for adding tests and additionally updating the eligible
endpoint to account for previously deleted webhooks.
I really appreciate you tackling this one! 🌟
src/fides/api/alembic/migrations/versions/9e83545ed9b6_pre_approval_webhook_cleanup.py
Show resolved
Hide resolved
src/fides/api/alembic/migrations/versions/9e83545ed9b6_pre_approval_webhook_cleanup.py
Show resolved
Hide resolved
src/fides/api/alembic/migrations/versions/9e83545ed9b6_pre_approval_webhook_cleanup.py
Show resolved
Hide resolved
# Check if all replies are true | ||
replies_for_privacy_request = PreApprovalWebhookReply.filter( | ||
db=db, | ||
conditions=(PreApprovalWebhookReply.privacy_request_id == privacy_request_id), | ||
).all() | ||
|
||
# Check if all replies are true. Reply ignored if its webhook has since been deleted. | ||
replies_for_privacy_request = ( | ||
db.query(PreApprovalWebhookReply) | ||
.filter( | ||
PreApprovalWebhookReply.privacy_request_id == privacy_request_id, | ||
PreApprovalWebhookReply.webhook_id.isnot(None), | ||
) | ||
.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.
Agree, and this additional check to ignore deleted webhooks is a good one 💯
webhook_id = Column( | ||
String, ForeignKey(PreApprovalWebhook.id_field_path), nullable=False | ||
String, | ||
ForeignKey(PreApprovalWebhook.id_field_path, ondelete="SET NULL"), index=True | ||
) |
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, this makes sense. For future reference, are there any disadvantages to setting an index
on a column at all?
Closes #PROD-2004
Description Of Changes
Autogenerating migrations reveals there are discrepancies between what is defined on the new PreApprovalWebhook and PreApprovalWebhookReply models and the tables in the fides application db. Let's get these in sync. Updating FK's, indices, etc. is trickier once we've started collecting data.
Code Changes
Add further handling if resources get deleted:
Steps to Confirm
Pre-Merge Checklist
CHANGELOG.md