Opened 19 years ago

Closed 19 years ago

Last modified 17 years ago

#712 closed defect (duplicate)

trunk django/core/meta/__init__.py in method_save(opts, self) raises exceptions.AttributeError (osx, mysql4, python24)

Reported by: levicook@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: blocker Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Interactive Session (ipython)

In [1]: from django.models.recipes import ingredients

In [2]: ingredients.get_count()
Out[2]: 0L

In [3]: ingredients.Ingredient??
Type:           ModelBase
Base Class:     <class 'django.core.meta.ModelBase'>
String Form:    <class 'django.models.recipes.Ingredient'>
Namespace:      Interactive
File:           /Users/levi/Projects/twistedrails.org/trunk/django/barmate/apps/recipes/models/recipes.py
Source:
class Ingredient (meta.Model):
    name = meta.CharField(maxlength=30)
    description = meta.TextField()
    parent_type = meta.ForeignKey('self')

    def __repr__(self):
        return '%s' % self.name

In [4]: i = ingredients.Ingredient()

In [5]: hasattr(i, 'id')
Out[5]: False

In [6]: hasattr(i, 'save')
Out[6]: True

In [7]: i.name = 'Milk'
In [7]: i.save()
---------------------------------------------------------------------------
exceptions.AttributeError                            Traceback (most recent call last)

/Users/levi/Projects/twistedrails.org/trunk/django/<console> 

/Users/levi/Projects/3rdParty/django_src/django/utils/functional.py in _curried(*moreargs, **morekwargs)
      1 def curry(*args, **kwargs):
      2     def _curried(*moreargs, **morekwargs):
----> 3         return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))
      4     return _curried

/Users/levi/Projects/3rdParty/django_src/django/core/meta/__init__.py in method_save(opts, self)
    781 
    782     # First, try an UPDATE. If that doesn't update anything, do an INSERT.
--> 783     pk_val = getattr(self, opts.pk.column)
    784     pk_set = bool(pk_val)
    785     record_exists = True

AttributeError: 'Ingredient' object has no attribute 'id'

svn info

levi@id ~/Projects/3rdParty/django_src
$ svn info
Path: .
URL: http://code.djangoproject.com/svn/django/trunk
Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37
Revision: 1032
Node Kind: directory
Schedule: normal
Last Changed Author: adrian
Last Changed Rev: 1031
Last Changed Date: 2005-10-30 21:17:39 -0600 (Sun, 30 Oct 2005)

uname -a

levi@id ~/Projects/3rdParty/django_src
$ uname -a
Darwin id.local 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC Power Macintosh powerpc

port active

levi@id ~/Projects/3rdParty/django_src
$ port installed 
The following ports are currently installed:
  bash-completion 20050721_0+dp_completion (active)
  bison 2.1_0 (active)
  coreutils 5.2.1_4 (active)
  libiconv 1.10_1+darwin_8 (active)
  lynx 2.8.5rel.2_0 (active)
  mysql4 4.1.14_1+darwin_8 (active)
  openssl 0.9.8a_0+darwin_8 (active)
  postgresql8 8.0.4_1+darwin_8 (active)
  py-ipython 0.6.15_0 (active)
  py-mx 2.0.5_1 (active)
  py-mysql 1.2.0_0 (active)
  py-psycopg 1.1.21_0+darwin_8 (active)
  py-readline 2.4.1_0 (active)
  python24 2.4.1_6 (active)
  readline 5.0.005_0+darwin_8 (active)
  ruby 1.8.2_6
  zlib 1.2.3_0 (active)

Change History (1)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #662.

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