Skip to content

ref(workflow_engine): Drop environment FK on Workflow model#110849

Open
beezz wants to merge 2 commits intomasterfrom
beezz/ref/workflow-drop-environment-fk
Open

ref(workflow_engine): Drop environment FK on Workflow model#110849
beezz wants to merge 2 commits intomasterfrom
beezz/ref/workflow-drop-environment-fk

Conversation

@beezz
Copy link
Copy Markdown
Contributor

@beezz beezz commented Mar 17, 2026

Replace the FlexibleForeignKey to sentry.Environment on the Workflow model with a plain BigIntegerField for environment_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 uses Environment.objects.get_from_cache() for explicit lookups, which is more efficient and decouples the models.

Changes

  • Model: environment = FlexibleForeignKey(...)environment_id = models.BigIntegerField(null=True, blank=True)
  • Processors/caches: Removed select_related("environment"), use get_from_cache or get_many_from_cache
  • Serializer: Batch-fetches environments in get_attrs() instead of traversing FK in serialize()
  • Validator: Converts environment object → environment_id in update path
  • Migration: Uses SeparateDatabaseAndState to drop FK constraint without touching column/data
  • Factory: create_workflow(environment=env) now auto-converts to environment_id=env.id

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>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 17, 2026
Comment thread src/sentry/workflow_engine/tasks/utils.py
@github-actions
Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0111_drop_workflow_environment_fk.py

for 0111_drop_workflow_environment_fk in workflow_engine

--
-- 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";

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Backend Test Failures

Failures on f383684 in this run:

tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py::TestEmailMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py::TestSlackMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_sentry_app_render_labellog
tests/sentry/api/serializers/test_rule.py:873: in test_sentry_app_render_label
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_reenable_disabled_rulelog
tests/sentry/api/endpoints/test_project_rule_details.py:1265: in test_reenable_disabled_rule
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_every_filterlog
tests/sentry/api/serializers/test_rule.py:444: in test_every_filter
    self.assert_equal_serializers(issue_alert)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py::TestPagerDutyMetricAlertHandler::test_send_alertlog
tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py:28: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_no_ownerlog
tests/sentry/api/endpoints/test_project_rule_details.py:714: in test_no_owner
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_no_conditions_multiple_filterslog
tests/sentry/api/serializers/test_rule.py:479: in test_no_conditions_multiple_filters
    self.assert_equal_serializers(issue_alert)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py::TestSlackMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_with_null_environmentlog
tests/sentry/api/endpoints/test_project_rule_details.py:1324: in test_with_null_environment
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_slack_actionlog
tests/sentry/api/serializers/test_rule.py:643: in test_slack_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py::TestEmailMetricAlertHandler::test_send_alertlog
tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py::TestOpsgenieMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py:28: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py::TestSentryAppMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py:32: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_get_new_statuslog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rules.py::ProjectRuleListTest::test_unsupported_conditionlog
tests/sentry/api/endpoints/test_project_rules.py:207: in test_unsupported_condition
    response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_jira_server_actionlog
tests/sentry/api/serializers/test_rule.py:768: in test_jira_server_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_rule_serializerlog
tests/sentry/api/serializers/test_rule.py:332: in test_rule_serializer
    self.assert_equal_serializers(issue_alert)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_discord_metric_alert_handler.py::TestDiscordMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_discord_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_issue_alert_registry_handlers.py::TestBaseIssueAlertHandler::test_create_rule_instance_from_actionlog
tests/sentry/notifications/notification_action/test_issue_alert_registry_handlers.py:140: in test_create_rule_instance_from_action
    assert self.workflow.environment is not None
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_build_alert_contextlog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::ProjectRuleDetailsTest::test_workflow_engine_serializer_dual_written_rulelog
tests/sentry/api/endpoints/test_project_rule_details.py:233: in test_workflow_engine_serializer_dual_written_rule
    response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/endpoints/test_project_rules.py::ProjectRuleListTest::test_workflow_enginelog
tests/sentry/api/endpoints/test_project_rules.py:148: in test_workflow_engine
    response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_github_actionlog
tests/sentry/api/serializers/test_rule.py:789: in test_github_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_invoke_legacy_registry_activity_empty_datalog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_send_alert_not_implementedlog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/workflow_engine/handlers/action/test_action_handlers.py::TestNotificationActionHandler::test_execute_error_group_typelog
tests/sentry/workflow_engine/handlers/action/test_action_handlers.py:17: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_simplelog
tests/sentry/api/endpoints/test_project_rule_details.py:688: in test_simple
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_update_owner_typelog
tests/sentry/api/endpoints/test_project_rule_details.py:743: in test_update_owner_type
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_discord_actionlog
tests/sentry/api/serializers/test_rule.py:617: in test_discord_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_msteams_metric_alert_handler.py::TestMsteamsMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_msteams_metric_alert_handler.py:31: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py::TestOpsgenieMetricAlertHandler::test_send_alertlog
tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py:28: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_jira_actionlog
tests/sentry/api/serializers/test_rule.py:747: in test_jira_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_pagerduty_actionlog
tests/sentry/api/serializers/test_rule.py:726: in test_pagerduty_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/api/endpoints/test_project_rules.py::CreateProjectRuleTest::test_workflow_enginelog
tests/sentry/api/endpoints/test_project_rules.py:1439: in test_workflow_engine
    response = self.get_success_response(
src/sentry/testutils/cases.py:641: in get_success_response
    assert_status_code(response, 200, 300)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 300
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_invoke_legacy_registry_with_activity_anomaly_detectionlog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::ProjectRuleDetailsTest::test_workflow_engine_serializer_single_written_rulelog
tests/sentry/api/endpoints/test_project_rule_details.py:242: in test_workflow_engine_serializer_single_written_rule
    response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_update_namelog
tests/sentry/api/endpoints/test_project_rule_details.py:974: in test_update_name
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_azure_devops_actionlog
tests/sentry/api/serializers/test_rule.py:831: in test_azure_devops_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_discord_metric_alert_handler.py::TestDiscordMetricAlertHandler::test_send_alertlog
tests/sentry/notifications/notification_action/metric_alert_registry/test_discord_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py::TestOpsgenieMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py:28: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py::TestPagerDutyMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py:28: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py::TestSlackMetricAlertHandler::test_send_alertlog
tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/workflow_engine/handlers/action/test_action_handlers.py::TestNotificationActionHandler::test_execute_unknown_detectorlog
tests/sentry/workflow_engine/handlers/action/test_action_handlers.py:17: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_reassign_owner_from_own_team_to_any_teamlog
tests/sentry/api/endpoints/test_project_rule_details.py:888: in test_reassign_owner_from_own_team_to_any_team
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_update_filterslog
tests/sentry/api/endpoints/test_project_rule_details.py:1532: in test_update_filters
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_github_enterprise_actionlog
tests/sentry/api/serializers/test_rule.py:810: in test_github_enterprise_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_msteams_actionlog
tests/sentry/api/serializers/test_rule.py:667: in test_msteams_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py::TestSentryAppMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py:32: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/projects/project_rules/test_updater.py::TestUpdater::test_dual_update_workflow_enginelog
tests/sentry/projects/project_rules/test_updater.py:168: in test_dual_update_workflow_engine
    assert workflow.environment is None
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_every_conditionlog
tests/sentry/api/serializers/test_rule.py:542: in test_every_condition
    self.assert_equal_serializers(issue_alert)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_build_notification_contextlog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_get_incident_statuslog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_with_environmentlog
tests/sentry/api/endpoints/test_project_rule_details.py:1293: in test_with_environment
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/notifications/notification_action/metric_alert_registry/test_msteams_metric_alert_handler.py::TestMsteamsMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_msteams_metric_alert_handler.py:31: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_slack_channel_id_saved_sdklog
tests/sentry/api/endpoints/test_project_rule_details.py:1410: in test_slack_channel_id_saved_sdk
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_team_owner_not_member_with_team_admin_scopelog
tests/sentry/api/endpoints/test_project_rule_details.py:842: in test_team_owner_not_member_with_team_admin_scope
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_opsgenie_actionlog
tests/sentry/api/serializers/test_rule.py:696: in test_opsgenie_action
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py::TestSentryAppMetricAlertHandler::test_send_alertlog
tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py:32: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_missing_occurrence_raises_value_errorlog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/workflow_engine/handlers/action/test_action_handlers.py::TestNotificationActionHandler::test_execute_metric_alert_typelog
tests/sentry/workflow_engine/handlers/action/test_action_handlers.py:17: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py::TestEmailMetricAlertHandler::test_invoke_legacy_registry_with_activitylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py:32: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_remove_conditionslog
tests/sentry/api/endpoints/test_project_rule_details.py:1011: in test_remove_conditions
    workflow_response = self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:47: in assert_status_code
    assert minimum <= response.status_code < maximum, (
E   AssertionError: (500, b'{"detail":"Internal Error","errorId":null}')
E   assert 500 < 201
E    +  where 500 = <Response status_code=500, "application/json">.status_code
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_email_action_simplelog
tests/sentry/api/serializers/test_rule.py:564: in test_email_action_simple
    self.assert_equal_serializers(rule)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_special_conditionlog
tests/sentry/api/serializers/test_rule.py:378: in test_special_condition
    self.assert_equal_serializers(issue_alert)
tests/sentry/api/serializers/test_rule.py:148: in assert_equal_serializers
    serialized_workflow_rule = serialize(
src/sentry/api/serializers/base.py:55: in serialize
    return serialize([objects], user=user, serializer=serializer, **kwargs)[0]
src/sentry/api/serializers/base.py:71: in serialize
    attrs = serializer.get_attrs(
src/sentry/api/serializers/models/rule.py:547: in get_attrs
    for workflow in workflows:
.venv/lib/python3.13/site-packages/django/db/models/query.py:386: in __iter__
    self._fetch_all()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1956: in _fetch_all
    self._prefetch_related_objects()
.venv/lib/python3.13/site-packages/django/db/models/query.py:1330: in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
.venv/lib/python3.13/site-packages/django/db/models/query.py:2383: in prefetch_related_objects
    raise AttributeError(
E   AttributeError: Cannot find 'environment' on Workflow object, 'environment' is an invalid parameter to prefetch_related()
tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py::TestPagerDutyMetricAlertHandler::test_invoke_legacy_registrylog
tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py:28: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_invoke_legacy_registry_activity_missing_datalog
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:291: in setUp
    super().setUp()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:164: in setUp
    self.create_models()
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:159: in create_models
    workflow_env=self.workflow.environment,
E   AttributeError: 'Workflow' object has no attribute 'environment'. Did you mean: 'environment_id'?
tests/sentry/api/serializers/test_rule.py::WorkflowRuleSerializerTest::test_ema

... (truncated due to GitHub comment size limit)

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.
@beezz beezz marked this pull request as ready for review March 18, 2026 11:13
@beezz beezz requested review from a team as code owners March 18, 2026 11:13
Copy link
Copy Markdown
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give some context on why this fk needs to be removed?

@getsantry
Copy link
Copy Markdown
Contributor

getsantry bot commented Apr 9, 2026

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 Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants