Opened 13 years ago

Closed 12 years ago

#16756 closed Bug (fixed)

Edit item with non integer value and inheritance fails on id.

Reported by: ck2329@… Owned by: nobody
Component: contrib.admin Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Start new project, create 3 models:

class Tr1(models.Model):
    en    = models.CharField(max_length=100)
    def __unicode__(self):
        return "%s"%(self.en)
    class Meta:
        ordering = ['en']
        
class Location2(models.Model):
    lon       = models.DecimalField(max_digits=9,decimal_places=6, blank=False)
    tr        = models.ForeignKey(Tr1,  unique=True) 
    
class Airport3(Location2):
    IATA    = models.CharField(primary_key=True, max_length=3, )
    def __unicode__(self):
        return "%s"%(self.pk)


Set default admin interfaces:

admin.site.register(Tr1)
admin.site.register(Location2)
admin.site.register(Airport3)

Now login into admin site, create Airport3 instance, save it. Open it again, modify anything, try to save. Exception will be raised: invalid literal for int() with base 10: 'ABC, where ABC is IATA field value.

Now remove tr field from Location2 model - repeat create&edit - everything works well.

Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\sites.py" in inner
  197.             return view(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "C:\Python26\lib\site-packages\django\db\transaction.py" in inner
  217.                 res = func(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in change_view
  962.             if form.is_valid():
File "C:\Python26\lib\site-packages\django\forms\forms.py" in is_valid
  121.         return self.is_bound and not bool(self.errors)
File "C:\Python26\lib\site-packages\django\forms\forms.py" in _get_errors
  112.             self.full_clean()
File "C:\Python26\lib\site-packages\django\forms\forms.py" in full_clean
  269.         self._post_clean()
File "C:\Python26\lib\site-packages\django\forms\models.py" in _post_clean
  337.             self.validate_unique()
File "C:\Python26\lib\site-packages\django\forms\models.py" in validate_unique
  346.             self.instance.validate_unique(exclude=exclude)
File "C:\Python26\lib\site-packages\django\db\models\base.py" in validate_unique
  638.         errors = self._perform_unique_checks(unique_checks)
File "C:\Python26\lib\site-packages\django\db\models\base.py" in _perform_unique_checks
  727.                 qs = qs.exclude(pk=self.pk)
File "C:\Python26\lib\site-packages\django\db\models\query.py" in exclude
  557.         return self._filter_or_exclude(True, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
  566.             clone.query.add_q(~Q(*args, **kwargs))
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py" in add_q
  1169.                     self.add_q(child, used_aliases, force_having=force_having)
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py" in add_q
  1172.                             can_reuse=used_aliases, force_having=force_having)
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py" in add_filter
  1107.                 connector)
File "C:\Python26\lib\site-packages\django\db\models\sql\where.py" in add
  67.             value = obj.prepare(lookup_type, value)
File "C:\Python26\lib\site-packages\django\db\models\sql\where.py" in prepare
  316.             return self.field.get_prep_lookup(lookup_type, value)
File "C:\Python26\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_lookup
  292.             return self.get_prep_value(value)
File "C:\Python26\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_value
  479.         return int(value)

Exception Type: ValueError at /admin/airsale/airport3/asd/
Exception Value: invalid literal for int() with base 10: 'asd'

Change History (2)

comment:1 by Travis Swicegood, 13 years ago

Triage Stage: UnreviewedAccepted

I've confirmed this against both 1.3 and the latest in trunk. It appears that the value of the IATA field is being treated as the pk and Django thinks that it needs to be converted to an integer. Definitely not expected behavior.

comment:2 by Ramiro Morales, 12 years ago

Resolution: fixed
Status: newclosed

This has been fixed at some point and doesn't fail on 1.5.x anymore.

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