Migration error on table `sentry_organizationcontributors` during upgrading to 26.7.1
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
26.7.0 から 26.7.1 へのアップグレードを再現し、sentry_organizationcontributors のマイグレーションエラーから始めてください。src/sentry/models/organizationcontributors.py、src/sentry/seer/code_review/contributor_seats.py、src/sentry/integrations/utils/hostname.py を読み、hostname の値がどのように作成されるかを追跡してください。アップグレードが無効または重複した Constraints なしで完了し、破壊的な手動データベース変更を必要としなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
You will face two kinds of error:
django.db.utils.IntegrityError: check constraint "sentry_organizationcontributors_hostname_6f7999b1_notnull" of relation "sentry_organizationcontributors" is violated by some row
SQL: ALTER TABLE "sentry_organizationcontributors" VALIDATE CONSTRAINT "sentry_organizationcontributors_hostname_6f7999b1_notnull"
From the source code, they described OrganizationContributors as:
Tracks external contributors and their activity for an organization.
This model stores information about contributors associated with an
integration for a specific organization, including their external identity
and how many actions they have taken.
The only INSERT query is here: https://github.com/getsentry/sentry/blob/ae93d339a993d4bf41add7ff86567d328bb58e5f/src/sentry/seer/code_review/contributor_seats.py#L150-L158
def get_or_create_contributor(
*,
organization: Organization,
integration: Integration | RpcIntegration,
external_identifier: str,
alias: str | None,
) -> OrganizationContributors | None:
"""
TODO(CW-1539): Replace with get_or_create() after the contributor deduplication
migration has completed.
"""
try:
hostname = instance_hostname(integration)
except InstanceHostnameError as e:
sentry_sdk.capture_exception(e)
return None
if contributor := get_canonical_contributor(
organization_id=organization.id,
integration=integration,
external_identifier=external_identifier,
):
return contributor
try:
with transaction.atomic(router.db_for_write(OrganizationContributors)):
return OrganizationContributors.objects.create(
organization_id=organization.id,
integration_id=integration.id,
external_identifier=external_identifier,
provider=integration.provider,
hostname=hostname,
alias=alias,
)
except IntegrityError:
contributor = get_canonical_contributor(
organization_id=organization.id,
integration=integration,
external_identifier=external_identifier,
)
if not contributor:
raise
return contributor
For my own case (the second one), the hostname fields are empty (null), therefore I need to update each fields to the source code management tool that I use (in this case, GitHub, therefore the value should be "github.com"). Refer to this code: https://github.com/getsentry/sentry/blob/ae93d339a993d4bf41add7ff86567d328bb58e5f/src/sentry/integrations/utils/hostname.py#L10-L32
Therefore the solution for this is changing the value directly on Postgres:
$ docker compose exec postgres psql -U postgres -d postgres
postgres=# SELECT * FROM sentry_organizationcontributors;
postgres=# UPDATE sentry_organizationcontributors SET hostname = 'github.com';
Then re-run ./install.sh.
When you execute it again, you might come across this error:
I get the following error when upgrading from 26.7.0
File "/.venv/lib/python3.13/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/.venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 103, in _execute return self.cursor.execute(sql) ~~~~~~~~~~~~~~~~~~~^^^^^ File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 16, in inner return func(self, *args, **kwargs) File "/usr/src/sentry/src/sentry/db/postgres/base.py", line 96, in execute return self.cursor.execute(sql) ~~~~~~~~~~~~~~~~~~~^^^^^ django.db.utils.ProgrammingError: constraint "sentry_organizationcontributors_hostname_6f7999b1_notnull" for relation "sentry_organizationcontributors" already exists SQL: ALTER TABLE "sentry_organizationcontributors" ADD CONSTRAINT "sentry_organizationcontributors_hostname_6f7999b1_notnull" CHECK ("hostname" IS NOT NULL) NOT VALID Error in install/set-up-and-migrate-database.sh:23. '$dcr web upgrade --create-kafka-topics' exited with status 1 -> ./install.sh:main:45 --> install/set-up-and-migrate-database.sh:source:23
Originally posted by @MagnusHBrunbjerg in #4426
The solution for this is to simply drop the constraint. Execute \d <table name> first to ensure the constraint is there. Then just drop it.
$ docker compose exec postgres psql -U postgres -d postgres
postgres=# \d sentry_organizationcontributors
Table "public.sentry_organizationcontributors"
Column | Type | Collation | Nullable | Default
---------------------+--------------------------+-----------+----------+----------------------------------
id | bigint | | not null | generated by default as identity
integration_id | bigint | | not null |
external_identifier | character varying(255) | | not null |
alias | character varying(255) | | |
num_actions | integer | | not null |
date_added | timestamp with time zone | | not null |
date_updated | timestamp with time zone | | not null |
organization_id | bigint | | not null |
provider | character varying(64) | | |
hostname | character varying(255) | | |
Indexes:
"sentry_organizationcontributors_pkey" PRIMARY KEY, btree (id)
"sentry_oc_org_date_upd_idx" btree (organization_id, date_updated)
"sentry_organizationcontr_external_identifier_ef77d39a_like" btree (external_identifier varchar_pattern_ops)
"sentry_organizationcontributors_external_identifier_ef77d39a" btree (external_identifier)
"sentry_organizationcontributors_integration_id_d13b5795" btree (integration_id)
"sentry_organizationcontributors_organization_id_93cc3a35" btree (organization_id)
"sentry_orgcont_unique_org_cont" UNIQUE CONSTRAINT, btree (organization_id, integration_id, external_identifier)
Check constraints:
"sentry_organizationcontributors_hostname_6f7999b1_notnull" CHECK (hostname IS NOT NULL) NOT VALID
Foreign-key constraints:
"sentry_organizationc_organization_id_93cc3a35_fk_sentry_or" FOREIGN KEY (organization_id) REFERENCES sentry_organization(id) DEFERRABLE INITIALLY DEFERRED
Referenced by:
TABLE "sentry_organizationcontributoraction" CONSTRAINT "sentry_organizationc_organization_contrib_db78e1a3_fk_sentry_or" FOREIGN KEY (organization_contributor_id) REFERENCES sentry_organizationcontributors(id) DEFERRABLE INITIALLY DEFERRED
postgres=# ALTER TABLE sentry_organizationcontributors DROP CONSTRAINT sentry_organizationcontributors_hostname_6f7999b1_notnull;
Then re-run ./install.sh.
Oh no, it's still happening!!!
Just truncate it and drop the constraint again.
$ docker compose exec postgres psql -U postgres -d postgres
postgres=# TRUNCATE TABLE sentry_organizationcontributors CASCADE;
postgres=# ALTER TABLE sentry_organizationcontributors DROP CONSTRAINT sentry_organizationcontributors_provider_4cfc5f3a_notnull;
- 主要言語
- Shell
- スター
- 9.7k
- フォーク
- 2k
- 平均マージ
- 3日 2時間
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
getsentry/self-hosted のほかの issue
-
Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
getsentry/self-hosted#4644 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
getsentry/self-hosted#4518 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Waiting for: Product Owner
難易度 3/5 1〜2日 初心者へのやさしさ 73/100
getsentry/self-hosted#4642 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Waiting for: Community
難易度 4/5 3〜5日 初心者へのやさしさ 28/100
getsentry/self-hosted#4637 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Waiting for: Product Owner
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
getsentry/self-hosted#4634 ·
メンテナーはふだん 2 日以内に返信
getsentry/self-hosted の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
ajithakdev/claude-desktop-rpm#43 ·
メンテナーはふだん 1 日以内に返信
-
documentation enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
aws/aws-networking-best-practices#256 ·
メンテナーはふだん 2 日以内に返信
-
area:terraform source:reader type:content-error
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
stephrobert/blog-roadmap#268 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
fossi-foundation/globalfoundries-pdk-libs-gf180mcu_fd_pv#61 ·
-
openai-directory
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100