hypothesis / hypothesis/h

IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if th...

Open
#5,551 0 comments 0 reactions 0 assignees View on GitHub
bug Python 3 S4 Sentry 💥
Dominant language
Python
Stars
3.2k
Forks
459
Avg merge
27d 1h
Merged PRs (30d)
1

Description

https://sentry.io/organizations/hypothesis/issues/856736679/?project=37293&referrer=github_plugin

```
IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (psycopg2.IntegrityError) duplicate key value violates unique constraint "uq__user_group__user_id"
DETAIL: Key (user_id, group_id)=(225407, 40059) already exists.
[SQL: 'INSERT INTO user_group (user_id, group_id) VALUES (%(user_id)s, %(group_id)s) RETURNING user_group.id'] [parameters: {'group_id': 40059, 'user_id': 225407}]
(35 additional frame(s) were not displayed)
...
File "sqlalchemy/util/compat.py", line 202, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "sqlalchemy/engine/base.py", line 1182, in _execute_context
context)
File "sqlalchemy/engine/default.py", line 469, in do_execute
cursor.execute(statement, parameters)
File "newrelic/hooks/database_psycopg2.py", line 51, in execute
**kwargs)
File "newrelic/hooks/database_dbapi2.py", line 25, in execute
*args, **kwargs)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked Sentry event and the reported SQLAlchemy stack trace, then trace the application path that inserts into the user_group table. The issue is resolved when the duplicate user/group relationship no longer produces this IntegrityError, with a regression test or reproducible verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
backend, databases
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.