Code

Opened 3 years ago

Closed 3 years ago

#15818 closed Bug (duplicate)

PostgreSQL autocommit mode breaks initial insert

Reported by: Rick@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Release blocker Keywords: postgresql, postgresql-9, autocommit
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Settings used:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django_test',           # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
        'OPTIONS': {
            'autocommit': True,
        },
    }
}

Code to reproduce:

from django.conf import settings
from django.contrib.auth.models import User
user = User(username='something')
user.save()

Stacktrace when executing:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    user.save()
  File "django/db/models/base.py", line 461, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "django/db/models/base.py", line 554, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "django/db/models/query.py", line 1434, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "django/db/models/sql/compiler.py", line 795, in execute_sql
    return self.connection.ops.fetch_returned_insert_id(cursor)
  File "django/db/backends/__init__.py", line 460, in fetch_returned_insert_id
    return cursor.fetchone()[0]
psycopg2.ProgrammingError: no results to fetch

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by Rick van Hattem <Rick.van.Hattem@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This was tested in a brand new project with the latest svn (r16025).

comment:2 Changed 3 years ago by Rick van Hattem <Rick.van.Hattem@…>

  • Keywords postgresql, postgresql-9, autocommit added

comment:3 Changed 3 years ago by kmtracey

  • Resolution set to duplicate
  • Status changed from new to closed

Sounds like #12180.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.