[Django] #20753: Beginner confused for MultiValueDictKeyError, where the error comes from?

27 views
Skip to first unread message

Django

unread,
Jul 15, 2013, 7:14:56 PM7/15/13
to django-...@googlegroups.com
#20753: Beginner confused for MultiValueDictKeyError, where the error comes from?
--------------------------------+------------------------------------
Reporter: adam.pahlevi@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Keywords: MultiValueDictKeyError
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
I am new to Django and would like to try it for my thesis project.
However, I found an error which is MultiValueDictKeyError when I try to
save my model from the Django admin.

I have 3 models in this case, which are: BSN (Business), LIN (Lines), ROT
(Routes).

BSN:
{{{#!python
class Bsn(models.Model):
"""The entity of business"""

#the enum for business type
BUSINESSTYPE = (
('bank', 'Bank'),
('barclub', 'Bar-Club'),
('carrental', 'Car rental'),
('church', 'Church'),
('clinic', 'Clinic'),
('cybercafe', 'Cybercafe'),
('exchange', 'Exchange'),
('festival', 'Festival'),
('fleamarket', 'Fleamarket'),
('hotel', 'Hotel'),
('mosque', 'Mosque'),
('police', 'Police'),
('primary', 'Primary'),
('restaurant', 'Restaurant'),
('secondary', 'Secondary'),
('shop', 'Shop'),
('sight', 'Sight'),
('transportation', 'Transportation'),
('uni', 'University')
)

bsnid = models.AutoField(primary_key=True)
id = bsnid.__str__()
bsnname = models.CharField("Business name", max_length=135,
unique=True)
bsntype = models.CharField("Business type", max_length=42,
choices=BUSINESSTYPE)
bsndesc = models.CharField("Description", max_length=135, blank=True)
bsnparent = models.ForeignKey('self', null=True,
db_column='bsnparent', blank=True)
bsncoorx = models.DecimalField("Coordination X in Map", null=True,
blank=True, max_digits=11, decimal_places=0)
bsncoory = models.DecimalField("Coordination Y in Map", null=True,
blank=True, max_digits=11, decimal_places=0)
bsncoorn = models.DecimalField("Coordination N in Map", null=True,
blank=True, max_digits=11, decimal_places=0)

def __unicode__(self):
return self.bsnname

class Meta:
db_table = u'bsn'
verbose_name="Business"
verbose_name_plural="Businesses"
}}}

Class LIN
{{{#!python
class Lin(models.Model):
"""model for the line"""
linid = models.AutoField(primary_key=True)
id = str(linid)
linbsn = models.ForeignKey(Bsn, db_column='linbsnid')

def __unicode__(self):
return "Line " + self.linbsn.bsnname

class Meta:
db_table = u'lin'
verbose_name = "Line"
}}}

And, the last but not least, ROT:
{{{#!python
class Rot(models.Model):
rotid = models.IntegerField(primary_key=True)
rotlin = models.ForeignKey(Lin, null=True, db_column='rotlinid',
blank=True)
rotfrom = models.ForeignKey(Trn, null=True, db_column='rotfrom',
blank=True, related_name="rotfrom")
rotto = models.ForeignKey(Trn, null=True, db_column='rotto',
blank=True, related_name="rotto")
rotkm = models.FloatField(null=True, blank=True)
rottimemnt = models.IntegerField(null=True, blank=True)
rotprice = models.FloatField(null=True, blank=True)
rotisinterchange = models.BooleanField(default=False, null=False,
blank=False, verbose_name="is interchange?")
rotisactive = models.BooleanField(default=True, null=False,
blank=False, verbose_name="is active?")
rotdesc = models.CharField(max_length=225, blank=True)

def __unicode__(self):
if self.rotfrom is None:
return "to " + str(self.rotto)
elif self.rotto is None:
return "from " + str(self.rotfrom)
else:
return "{0} to {1}".format(self.rotfrom.bsnid.bsnname,
self.rotto.bsnid.bsnname)

class Meta:
db_table = u'rot'
verbose_name = "Route"
}}}

The model are generated from inspectdb, and all is working when I try to
save one by one manually; both from Django admin and from the Django
console, and also from a Pilot.py file that I myself created to fill the
database automatically whenever I want, with initial data.

But, when I go to admin page for LIN, that itself is a 'child' of BSN and
that itself is used to determine and show the ROT; I got the multivalued
key error. I have tried to understand this error, but I lost myself. I
have no one at hand to help except than the Django community here. So,
please let me know where I am wrong at.

Here are the Admin code.
{{{#!python
class RotAdmin(admin.ModelAdmin):
"""admin page for route"""
fieldsets = [
(None, {'fields': ['rotlin', 'rotfrom', 'rotto',
'rotisinterchange', 'rotisactive']}),
("Distance", {'fields': ['rotkm', 'rottimemnt', 'rotprice']}),
("Description", {'fields': ['rotdesc']})
]
admin.site.register(Rot, RotAdmin)

class RotGridsTabular(admin.TabularInline):
fields = ['rotfrom', 'rotto', 'rotkm', 'rottimemnt', 'rotprice',
'rotisinterchange', 'rotisactive']
model = Rot
extra = 0

class LinAdmin(admin.ModelAdmin):
"""admin page for line"""
fields = ['linbsn']
inlines = [RotGridsTabular]
admin.site.register(Lin, LinAdmin)
}}}

Note: when I add the ROT record from the ROT admin, it works; when I add
the ROT record from LIN admin, it crashes and throws the Multivalued key
error.

--
Ticket URL: <https://code.djangoproject.com/ticket/20753>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 15, 2013, 8:42:17 PM7/15/13
to django-...@googlegroups.com
#20753: Beginner confused for MultiValueDictKeyError, where the error comes from?
-------------------------------------+-------------------------------------

Reporter: adam.pahlevi@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage:
MultiValueDictKeyError | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by CollinAnderson):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

My guess is there's a Rot that's should be showing on /admin/levi/lin/40/,
but it's not showing up, possibly because of bad data. Try getting
Lin.objects.get(pk=40).rot_set.all()[0], and seeing if there's any bad or
strange data for that Rot object.

Also, for best results, try upgrading to django 1.5, because it may be
that the error you are running into has been fixed.

--
Ticket URL: <https://code.djangoproject.com/ticket/20753#comment:1>

Django

unread,
Jul 15, 2013, 11:22:03 PM7/15/13
to django-...@googlegroups.com
#20753: Beginner confused for MultiValueDictKeyError, where the error comes from?
-------------------------------------+-------------------------------------

Reporter: adam.pahlevi@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage:
MultiValueDictKeyError | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anonymous):

Replying to [comment:1 CollinAnderson]:


> My guess is there's a Rot that's should be showing on
/admin/levi/lin/40/, but it's not showing up, possibly because of bad
data. Try getting Lin.objects.get(pk=40).rot_set.all()[0], and seeing if
there's any bad or strange data for that Rot object.
>
> Also, for best results, try upgrading to django 1.5, because it may be
that the error you are running into has been fixed.

Okay I will try your suggestion. Thanks.

For that particular reason as of why I am not using Django 1.5 is because
I need MySQL, because the data also consumed by Java program, I don't want
to switch to Postgres and change the driver and anything it is, I don't
use ORM as I like SQL for better performance. So, unless I can use MySQL
in Django 1.5 or Python 3.3 or the latest, I will stick with the old
version unfortunately enough.

Thanks for the dedication to check the problem. And I will report it soon
afterwards.

--
Ticket URL: <https://code.djangoproject.com/ticket/20753#comment:2>

Django

unread,
Jul 18, 2013, 5:56:13 PM7/18/13
to django-...@googlegroups.com
#20753: Beginner confused for MultiValueDictKeyError, where the error comes from?
-------------------------------------+-------------------------------------
Reporter: adam.pahlevi@… | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
MultiValueDictKeyError | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kmtracey):

* status: new => closed
* resolution: => duplicate


Comment:

I believe the underlying problem here is same as #13696

--
Ticket URL: <https://code.djangoproject.com/ticket/20753#comment:3>

Reply all
Reply to author
Forward
0 new messages