Opened 14 years ago

Closed 14 years ago

#15818 closed Bug (duplicate)

PostgreSQL autocommit mode breaks initial insert

Reported by: Rick@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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

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

Change History (3)

comment:1 by Rick van Hattem <Rick.van.Hattem@…>, 14 years ago

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

comment:2 by Rick van Hattem <Rick.van.Hattem@…>, 14 years ago

Keywords: postgresql postgresql-9 autocommit added

comment:3 by Karen Tracey, 14 years ago

Resolution: duplicate
Status: newclosed

Sounds like #12180.

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