Opened 9 years ago

Closed 9 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: no UI/UX: no


Settings used:

    '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')

Stacktrace when executing:

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

Change History (3)

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

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

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

Keywords: postgresql postgresql-9 autocommit added

comment:3 Changed 9 years ago by Karen Tracey

Resolution: duplicate
Status: newclosed

Sounds like #12180.

Note: See TracTickets for help on using tickets.
Back to Top