ref(workflow_engine): Drop environment FK on Workflow model#110849
Open
ref(workflow_engine): Drop environment FK on Workflow model#110849
Conversation
Replace the FlexibleForeignKey to sentry.Environment with a plain BigIntegerField for environment_id. This removes the FK constraint while keeping the column and data intact. All code that previously traversed the FK relationship now uses Environment.objects.get_from_cache() for explicit lookups, which is more efficient and decouples the models. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
This PR has a migration; here is the generated SQL for for --
-- Custom state/database change combination
--
SET CONSTRAINTS "workflow_engine_work_environment_id_905d91b4_fk_sentry_en" IMMEDIATE; ALTER TABLE "workflow_engine_workflow" DROP CONSTRAINT "workflow_engine_work_environment_id_905d91b4_fk_sentry_en";
DROP INDEX CONCURRENTLY IF EXISTS "workflow_engine_workflow_environment_id_905d91b4"; |
Contributor
Backend Test FailuresFailures on
|
Replace all usages of `workflow.environment` (related object access) with `workflow.environment_id` or Environment lookups, since the FK was dropped in favor of a plain BigIntegerField.
wedamija
reviewed
Mar 18, 2026
Member
wedamija
left a comment
There was a problem hiding this comment.
Could you give some context on why this fk needs to be removed?
Contributor
|
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you remove the label "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the
FlexibleForeignKeytosentry.Environmenton theWorkflowmodel with a plainBigIntegerFieldforenvironment_id. This drops the FK constraint while keeping the column and all existing data intact.All code that previously traversed the FK relationship (
self.environment,select_related("environment")) now usesEnvironment.objects.get_from_cache()for explicit lookups, which is more efficient and decouples the models.Changes
environment = FlexibleForeignKey(...)→environment_id = models.BigIntegerField(null=True, blank=True)select_related("environment"), useget_from_cacheorget_many_from_cacheget_attrs()instead of traversing FK inserialize()environmentobject →environment_idin update pathSeparateDatabaseAndStateto drop FK constraint without touching column/datacreate_workflow(environment=env)now auto-converts toenvironment_id=env.id