Code

Opened 4 years ago

Closed 4 years ago

#12665 closed (invalid)

get_or_create fails with self as a parameter

Reported by: timo Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: get_or_create deepcopy TypeError
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I believe this bug was introduced in changeset [11916].

I have the following code (abbreviated) which works fine on Django 1.1:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    client = models.ForeignKey(Client)

class Client(models.Model):
    def create_login(self):
        UserProfile.objects.get_or_create(
            user = user,
            client = self,
        )

However, the create_login method generates the following traceback with the latest SVN checkout:

  File "/home/tim/code/python/django-trunk/django/db/models/manager.py", line 135, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/home/tim/code/python/django-trunk/django/db/models/query.py", line 364, in get_or_create
    return self.get(**kwargs), False
  File "/home/tim/code/python/django-trunk/django/db/models/query.py", line 333, in get
    clone = clone.order_by()
  File "/home/tim/code/python/django-trunk/django/db/models/query.py", line 637, in order_by
    obj = self._clone()
  File "/home/tim/code/python/django-trunk/django/db/models/query.py", line 737, in _clone
    query = self.query.clone()
  File "/home/tim/code/python/django-trunk/django/db/models/sql/query.py", line 228, in clone
    obj.where = deepcopy(self.where)
  File "/usr/lib/python2.5/copy.py", line 173, in deepcopy
    y = copier(memo)
  File "/home/tim/code/python/django-trunk/django/utils/tree.py", line 61, in __deepcopy__
    obj.children = deepcopy(self.children, memodict)
  File "/usr/lib/python2.5/copy.py", line 162, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.5/copy.py", line 227, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib/python2.5/copy.py", line 162, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.5/copy.py", line 234, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "/usr/lib/python2.5/copy.py", line 189, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.5/copy.py", line 337, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.5/copy.py", line 162, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.5/copy.py", line 254, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.5/copy.py", line 181, in deepcopy
    rv = reductor(2)
TypeError: 'NoneType' object is not callable

I can try to work up a test if this looks to be a valid bug.

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by timo

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

Actually I have tracked this down to r11952 (merge of multi-db).

comment:2 Changed 4 years ago by timo

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

looks to be caused by some hackish code in the app I'm working on.

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.