Code

Opened 6 years ago

Closed 6 years ago

#6760 closed (fixed)

Updating inherited models doest not work with customs defaults managers

Reported by: Arnaud Rebts Owned by: nobody
Component: Database layer (models, ORM) Version: queryset-refactor
Severity: Keywords:
Cc: arnaud.rebts@… Triage Stage: Unreviewed
Has patch: no Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: UI/UX:

Description

Here is the code that cause the bug:

class MovieManager(models.Manager):
    def get_query_set(self):
        """Do not return episodes"""
        return super(MovieManager, self).get_query_set().filter(_class='Movie')

class Item(models.Model):
    _class = models.CharField(max_length=100)
    
class Movie(Item):
    objects = MovieManager()
    descript = models.CharField(max_length=255, blank=True)

class Episode(Movie):
    pass

Then, if I do the followings:

m = Movie(_class='Movie')
m.save()
m.save()

I get the following traceback with PostgreSQL :

Traceback (most recent call last):
  File "/opt/local/lib/python2.5/site-packages/django/test/_doctest.py", line 1267, in __run
    compileflags, 1) in test.globs
  File "<doctest bugfix.update_not_working.models.Movie[2]>", line 1, in <module>
    m.save()
  File "/Users/kid/Code/Django/bugfix/../bugfix/update_not_working/models.py", line 14, in save
    super(Item, self).save()
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 261, in save
    self.save_base()
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 301, in save_base
    manager.filter(pk=pk_val).update(**dict(values))
  File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 259, in update
    query.execute_sql(None)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 112, in execute_sql
    super(UpdateQuery, self).execute_sql(result_type)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 1269, in execute_sql
    cursor.execute(sql, params)
ProgrammingError: subquery has too many columns

And with SQLite3:

Traceback (most recent call last):
  File "/opt/local/lib/python2.5/site-packages/django/test/_doctest.py", line 1267, in __run
    compileflags, 1) in test.globs
  File "<doctest bugfix.update_not_working.models.Movie[2]>", line 1, in <module>
    m.save()
  File "/Users/kid/Code/Django/bugfix/../bugfix/update_not_working/models.py", line 14, in save
    super(Item, self).save()
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 261, in save
    self.save_base()
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 301, in save_base
    manager.filter(pk=pk_val).update(**dict(values))
  File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 259, in update
    query.execute_sql(None)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 112, in execute_sql
    super(UpdateQuery, self).execute_sql(result_type)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 1269, in execute_sql
    cursor.execute(sql, params)
  File "/opt/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 136, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: only a single result allowed for a SELECT that is part of an expression

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by mtredinnick

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

(In [7234]) queryset-refactor: Made sure that update filter queries only return a single
column. Fixed #6760.

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.