feat(iswf): Adds Issue label, org label coarse data model#114925
feat(iswf): Adds Issue label, org label coarse data model#114925GabeVillalobos wants to merge 2 commits intomasterfrom
Conversation
| """ | ||
| Update an IssueLabel by id. | ||
|
|
||
| Invalidates the cache for the owning issue. |
There was a problem hiding this comment.
IssueLabel.update() raises DoesNotExist on missing/deleted record
IssueLabel.objects.get(id=issue_label_id) is called without handling IssueLabel.DoesNotExist. If the label was deleted concurrently or the ID is stale/invalid (e.g., from an API request), this raises an unhandled exception that propagates as a 500. Service-layer mutation entry points should surface a graceful error so callers can return 404.
Verification
Reviewed the service module in the hunk. update, delete, update_org_label, and delete_org_label all call Model.objects.get(id=...) with no try/except and no .filter().first() guard. This matches Check 2 (Missing Record / Stale Reference) — service-layer methods consumed by API endpoints should not raise DoesNotExist uncaught. No parent endpoint validation exists since this is a generic service.
Also found at 2 additional locations
src/sentry/issues/services/issue_label/service.py:65-65src/sentry/issues/services/issue_label/service.py:99-99
Identified by Warden sentry-backend-bugs · M4X-WM4
| """Create a new IssueLabel and invalidate the cache for its issue.""" | ||
| issue_label = IssueLabel.objects.create( | ||
| group_id=group_id, | ||
| label_id=label_id, | ||
| label_value=label_value, |
There was a problem hiding this comment.
create() and create_org_label() do not handle unique constraint violations
IssueLabel.objects.create() and OrganizationLabel.objects.create() are called without handling IntegrityError. If unique constraints exist (likely for (group_id, label_id) on IssueLabel and (organization_id, label_name) on OrganizationLabel based on typical label data models), duplicate creation requests will raise an unhandled IntegrityError resulting in a 500. This is Check 7 (Database Constraint Violations).
Verification
Read the create() and create_org_label() methods in the hunk. Cannot confirm exact unique constraints without reading src/sentry/models/issuelabel.py and src/sentry/models/organizationlabel.py (listed as other files in PR but not provided), but label models almost universally enforce uniqueness on (scope, name). Reporting at medium confidence since the constraint definitions aren't visible — the pattern (unguarded create on a label model) is a well-known precedent for IntegrityError issues.
Identified by Warden sentry-backend-bugs · GAX-S46
|
This PR has a migration; here is the generated SQL for for --
-- Create model OrganizationLabel
--
CREATE TABLE "sentry_organizationlabel" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "label_name" varchar(255) NOT NULL, "organization_id" bigint NOT NULL);
--
-- Create model IssueLabel
--
CREATE TABLE "sentry_issuelabel" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "label_value" varchar(255) NOT NULL, "group_id" bigint NOT NULL, "label_id" bigint NOT NULL);
CREATE UNIQUE INDEX CONCURRENTLY "sentry_organizationlabel_organization_id_label_na_43e8691b_uniq" ON "sentry_organizationlabel" ("organization_id", "label_name");
ALTER TABLE "sentry_organizationlabel" ADD CONSTRAINT "sentry_organizationlabel_organization_id_label_na_43e8691b_uniq" UNIQUE USING INDEX "sentry_organizationlabel_organization_id_label_na_43e8691b_uniq";
ALTER TABLE "sentry_organizationlabel" ADD CONSTRAINT "sentry_organizationl_organization_id_2c47abec_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_organizationlabel" VALIDATE CONSTRAINT "sentry_organizationl_organization_id_2c47abec_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_organizationlabel_organization_id_2c47abec" ON "sentry_organizationlabel" ("organization_id");
ALTER TABLE "sentry_issuelabel" ADD CONSTRAINT "sentry_issuelabel_group_id_396a723a_fk_sentry_groupedmessage_id" FOREIGN KEY ("group_id") REFERENCES "sentry_groupedmessage" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_issuelabel" VALIDATE CONSTRAINT "sentry_issuelabel_group_id_396a723a_fk_sentry_groupedmessage_id";
ALTER TABLE "sentry_issuelabel" ADD CONSTRAINT "sentry_issuelabel_label_id_fb39a67f_fk_sentry_or" FOREIGN KEY ("label_id") REFERENCES "sentry_organizationlabel" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_issuelabel" VALIDATE CONSTRAINT "sentry_issuelabel_label_id_fb39a67f_fk_sentry_or";
CREATE INDEX CONCURRENTLY "sentry_issuelabel_group_id_396a723a" ON "sentry_issuelabel" ("group_id");
CREATE INDEX CONCURRENTLY "sentry_issuelabel_label_id_fb39a67f" ON "sentry_issuelabel" ("label_id");
CREATE INDEX CONCURRENTLY "sentry_issu_group_i_0f746e_idx" ON "sentry_issuelabel" ("group_id", "label_id"); |
Backend Test FailuresFailures on
|
----PROTOTYPE----
Coarse data model, service, and caching layer for issue and organization-scoped labels.