Skip to content

Error during 0024_auto_20191230_2052 migration #322

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

Closed
Fogapod opened this issue Jan 8, 2020 · 6 comments · Fixed by getsentry/sentry#16364
Closed

Error during 0024_auto_20191230_2052 migration #322

Fogapod opened this issue Jan 8, 2020 · 6 comments · Fixed by getsentry/sentry#16364
Assignees

Comments

@Fogapod
Copy link

Fogapod commented Jan 8, 2020

I tried upgrading my 9.12 installation to 10 and this error happened during database migration:

Applying sentry.0024_auto_20191230_2052...Events to process: 802
Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/__init__.py", line 164, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/decorators.py", line 30, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/commands/upgrade.py", line 168, in upgrade
    _upgrade(not noinput, traceback, verbosity, not no_repair)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/commands/upgrade.py", line 130, in _upgrade
    ignore_ghost_migrations=True,
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python2.7/site-packages/sentry/new_migrations/monkey/executor.py", line 26, in apply_migration
    state, migration, fake=fake, fake_initial=fake_initial
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 183, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/usr/local/lib/python2.7/site-packages/sentry/migrations/0024_auto_20191230_2052.py", line 62, in backfill_eventstream
    for event in RangeQuerySetWrapper(events, step=100, callbacks=(_attach_related,)):
  File "/usr/local/lib/python2.7/site-packages/sentry/utils/query.py", line 83, in __iter__
    cb(results)
  File "/usr/local/lib/python2.7/site-packages/sentry/migrations/0024_auto_20191230_2052.py", line 46, in _attach_related
    event.group = groups[event.group_id]
KeyError: 22L

Looks like my database is a bit broken, one project got deleted, but there are still references to it from some tables. I had an error in previous migration too and had to delete some rows from tables that pointed to deleted project_id. This error is probably related to that too, but I don't understand what exactly causes it and what can I do.

How can I fix this?

I have a backup of my database volume and can try different solutions.

@BYK
Copy link
Member

BYK commented Jan 9, 2020

Oh, this is probably something we can protect against but I need our expert on this: @lynnagara - any ideas?

@Fogapod
Copy link
Author

Fogapod commented Jan 9, 2020

I can't reproduce this anymore for some reason. This worked the same way yesterday when I tested this multiple times. Now I always get different error running same commands:

sudo rm -rf /var/lib/docker/volumes/sentry-postgres
sudo cp ~/sentry-postgres /var/lib/docker/volumes/ -r
./install.sh

gives me

Faking migration for contenttypes.0001_initial
Faking migration for contenttypes.0002_remove_content_type_name
Faking migration for auth.0001_initial
Faking migration for auth.0002_alter_permission_name_max_length
Faking migration for auth.0003_alter_user_email_max_length
Faking migration for auth.0004_alter_user_username_opts
Faking migration for auth.0005_alter_user_last_login_null
Faking migration for auth.0006_require_contenttypes_0002
Faking migration for sites.0001_initial
Faking migration for admin.0001_initial
Faking migration for sessions.0001_initial
Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/__init__.py", line 164, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/decorators.py", line 30, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/commands/upgrade.py", line 168, in upgrade
    _upgrade(not noinput, traceback, verbosity, not no_repair)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/commands/upgrade.py", line 130, in _upgrade
    ignore_ghost_migrations=True,
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 130, in call_command
    return command.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
    executor.loader.check_consistent_history(connection)
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 292, in check_consistent_history
    connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration jira_ac.0001_initial is applied before its dependency sentry.0003_auto_20191022_0122 on database 'default'.

every time. Database backup was not changed, sentry 9.12 runs with it without problems.
Should I open a new issue?

@BYK
Copy link
Member

BYK commented Jan 9, 2020

@Fogapod, yes, can you file a new issue for this second one. I'm fairly sure it is due to a missing line over at https://github.com/getsentry/sentry/blob/2ee72b121658496633e71d77f34e006de88a220b/src/sentry/conf/server.py#L1739-L1741 and I hope to resolve this one very soon with the help of @wedamija. I'm guessing you had the Jira plugin installed earlier? (or just sentry-plugins?)

@Fogapod
Copy link
Author

Fogapod commented Jan 9, 2020

I'm nots sure, I had github plugin installed before but I'm not using it anymore, it might got uninstalled at some point

@BYK
Copy link
Member

BYK commented Jan 9, 2020

All plugins are now baked in so no need to install them anymore and that would explain the issue as at some point you had the Jira plugin installed too (as part of the sentry-plugins package), having the migration applied earlier. Submitted a potential fix and hoping to resolve it by EOD today.

BYK added a commit to getsentry/sentry that referenced this issue Jan 9, 2020
@BYK BYK self-assigned this Jan 9, 2020
matejminar added a commit to getsentry/sentry that referenced this issue Jan 13, 2020
* ref(ts): Convert <SidebarOrgSummary> to typescript

* comment

* fix: Use django's is_safe_url function (#16337)

The implementation of this function from django 1.9.13 covers more invalid URLs
than the one from django-sudo does. We should not redirect to
`http:123347` style URLs.

* fix(ui) Fix gravatar fallbacks (#16336)

When updating Gravatar to typescript, I removed some property spreads as
they triggered typescript warnings and the propTypes didn't cover any
props that needed spreading. The onLoad and onError props were load
bearing as they are used to handle gravatar fallbacks.

* Removing unused class (#16278)

* fix(discover) - Show errors if we encounter them loading discover

- Shows a permission error if a user without access to events like a
  billing account tries to access discover

* feat(discover) Switch trace and span id to use columns instead of context

Have the trace_id and span_id use the built in columns instead of the context
array.

* fix(ui): Fix <ContextPickerModal> and refactor to ts (#16090)

This removes `LatestContext` dependency and fixes `ContextPickerModal` and refactors it to ts.

Co-Authored-By: Matej Minar <[email protected]>

* fix(ui): Fix redirect after creating/editing Metric Alert rules (#16342)

Also makes sure that the index redirects to combined alert listing view.

* ref(perf) Attempt to improve performance of facets endpoint (#16359)

* Fetch tag values individually. This will let snuba use the promoted
  columns more effectively as they perform better.
* Only get 10 facets by default.
* Use a having clause instead of WHERE to exclude tracing tags as it
  performs better.
* Don't use fields that unpack into arrayJoin() expressions where
  possible.
* Enable sampling at lower project thresholds, as we don't need full
  accuracy.

* fix(saml2): Improve error message on attribute mapping (#16347)

* ref: Remove SnubaEvent (#16309)

Remove SnubaEvent since we are moving towards a single event model
(eventstore/models/Event) everywhere.

* fix(tasks) Add event data to user report asynchronously

If an event hasn't been propagated when the user report is created, then queue a
task to sync the event data once it's stored fully.

* feat(django): pytest startup and test collection on Django 1.11 (#16105)

* chore: cleanup bitfield (#16031)

* fix(migrations): Make Snuba event migration more robust (#16364)

Fixes getsentry/self-hosted#322

* feat(teams): Update open membership team permissions (#16244)

* fix(migrations): Fix prerequisite for jira_ac migration (#16351)


Fixes getsentry/self-hosted#332

* fix(auth): Correct path used for SSO errors (#16315)

The route for sentry-organization-auth-settings was still located in the
old settings path, this route is used for a redirect in the auth.helper
module when there is a problem configuring SSO.

This just corrects the redirect so it goes back to settings instead of
404ing.

* fix: Remove beta tag on PagerDuty integration (#16344)

* fix(tagstore) Don't explode on null values (#16368)

The `sentry:user` tag can come back null when it is read from the
promoted columns. Handling nulls allows get_tag_value_label() to be used
more broadly.

* ref: Remove now unused discover query code (#16306)

Remove the automatic dataset detection logic from sentry. We have
switched over to the snuba based implementation of this. Not having
dataset selection in sentry also means we can remove some (but not all)
of the supporting logic as well.

* feat(ui): Require `org:write` role for Metric Alerts form (#16340)

This disables all form fields when editing a Metric Alert without the `org:write` role.

* ref(ts) Move BadgeDisplayName to typescript (#16361)

* test: fix remaining Django 1.11 tests and make required (#16367)

* fix(saml): Wrap individual idp config tabs with forms (#16373)

* chore(django 1.11): bump django-crispy-forms to 1.7.2 (#16371)

* translation+pluralization

* removed duplicate style

* removed duplicate style

* fix(ui): Fixed alignment in <TogglableAddress> if it cannot be converted to relative (#16385)

* ref(discover2) Test out sampling on tag values (#16387)

The facets endpoint is still not fast. I want to see what kind of
results can be obtained if we aggressively sample tag values. If this
yields acceptable performance I want to try scaling the sampling rate
based on the data volume so that we can better balance accurracy and
performance.

* test(acceptance): Try #2 to fix flakey onboarding test for dja… (#16345)

Try #2, use a timed retry policy

* fix(discover2): Fix Percy snapshots and UX issues on Querybuilder (#16291)

* fix(discover2): Test fix on Percy snapshots
* fix(discover2): Improve QueryBuilder for error/loading states
* fix(discover2): Resize QueryBuilder when browser is resized

* feat: Register option for eventstream (#16363)

Register option for #16285

* feat(alerts): Remove "Related issues" from incidents (#16379)

This removes the UI components that fetch and render related issues on the Incidents details view.

* ref: Deprecate get_legacy_message (#16310)

Move the implementation into the Pagerduty plugin since this is the only
place it is used.

* feat(tracing) Add spans for snuba queries (#16388)

Add spans to collect more information about snuba queries. Having the
referrer and the start of the query body should make tracking down slow
queries in snuba easier as we have more context.

* feat(workflow): Remove "Create incident" manual workflow and e… (#16375)

This removes the UI and endpoint to create a manual incident.

* feat: upgrade drf to 3.6.4 (#16392)

* feat(alerts): Remove "Suspects" UI and endpoint (#16378)

This was used on the Incidents details view, but is no longer used

* ref(discover) Remove the raw field (#16390)

Outputting the raw data when we also output all the formatted keys
wastes space and adds visual noise.

* fix(discover2): Use transaction root span only if there are no descendent spans for the ops breakdown (#16377)

* feat(emotion): Upgrade emotion to v10 (#15106)

* ref(ui): Refactor `cx` from emotion to `classnames`

We generally use the `classnames` library to handle merging/dynamic `className`. No reason to use two different libraries.

* upgrade emotion, add styled wrapper for typings (and related paths), add eslint rules for emotion, update babel plugin

* Refactor usage of emotion `css` being treated as a class name string

* change innerRef --> ref

* refactor grid-emotion props and update to `reflexbox`

* eslint for emotion-setup

* refactor injectGlobal --> Global for emotion upgrade

* Add <CacheProvider>, this is needed to turn speedy off for percy

* refactor <HeaderItem> - fix missing props to styled components, remove innerRef and forwardRef

* Change <Tooltip> logic for when to apply a wrapper, emotion causes the previously expected types to be different

* random TS fixes for styled components

* fix <RadioGroup> animation needing `css`

* forwardRef for Switch

* define a `theme.space` for rebass/grid

* fix DOM attribute warnings with "loading" prop

* fix settings breadcrumb - Box in `reflexbox` has different CSS than grid-emotion

* change <ProviderRow> to remove `Flex` around CircleIndicator as it was squishing it on small widths

* css fixes for percy

* fix featureDisabled logic for custom alerts because emotion

* refactor emotion9 --> emotion10 (imports)

* update snapshots and fix tests

* feat(drf): Add CamelSnakeSerializer (#16397)

* docs(workflow): Fix link to screenshots in README.md (#16404)

Fixes links to screenshots in README.md broken by 983c8c6

* ref(ts): Convert <QueryCount> to typescript (#16356)

* ref(ts): Convert <SearchBar> to typescript (#16357)

* ref(ts): Convert <SearchBar> to typescript

* removed proptypes, placeholder optional

* ref(ts): Convert getOnboardingTasks to typescript (#16348)

* merge

Co-authored-by: Mark Story <[email protected]>
Co-authored-by: Chris Fuller <[email protected]>
Co-authored-by: William Mak <[email protected]>
Co-authored-by: evanh <[email protected]>
Co-authored-by: Billy Vong <[email protected]>
Co-authored-by: Evan Purkhiser <[email protected]>
Co-authored-by: Lyn Nagara <[email protected]>
Co-authored-by: josh <[email protected]>
Co-authored-by: Burak Yigit Kaya <[email protected]>
Co-authored-by: Megan Heskett <[email protected]>
Co-authored-by: NisanthanNanthakumar <[email protected]>
Co-authored-by: Danny Lee <[email protected]>
Co-authored-by: Alberto Leal <[email protected]>
Co-authored-by: Aakash Kambuj <[email protected]>
@servomac
Copy link

servomac commented Aug 5, 2020

I have fixed first reported error directly deleting a few events referencing not existing groups:

DELETE from sentry_message where id in (select M.id from sentry_message M left join sentry_groupedmessage G on G.id = M.group_id where G.id IS NULL)

@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants