Opened 4 years ago

Closed 3 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


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"%(

Set default admin interfaces:

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.

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 3 years ago by ramiro

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

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