Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#540 closed defect (fixed)

ManyToManyField gives error with blank, raw_id_admin and empty input

Reported by: wojtek3@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If you define the following field:

    tags = meta.ManyToManyField(Tag, blank=True, raw_id_admin=True)

And provide no input for the 'tags' field in the HTML form for the addition of the given model. You get this error (although blank=True should cause it to work fine):

There's been an error:

Traceback (most recent call last):

  File "d:\django\django\core\handlers\", line 64, in get_response
    response = callback(request, **param_dict)

  File "i:\projects\grono2\contrib\web\", line 51, in create_object
    new_object =

  File "d:\django\django\utils\", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "d:\django\django\core\meta\", line 1483, in manipulator_save
    was_changed = getattr(new_object, 'set_%s' %

  File "d:\django\django\utils\", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "d:\django\django\core\meta\", line 896, in method_set_many_to_many
    id_list = map(int, id_list) # normalize to integers

ValueError: invalid literal for int(): 

Change History (3)

comment:1 Changed 13 years ago by Adrian Holovaty

Is the primary key in your Tag model a non-integer? If so, this is a known issue, and I have a fix on my local machine.

comment:2 Changed 13 years ago by wojtek3@…

Here's how Tag looks. Default primary key.

class Tag(meta.Model):
    name = meta.CharField('name', maxlength=150, unique=True)
    user = meta.ForeignKey(User)
    # typ taga, 0 - generyczny, reszta do zarezerwowania
    type = meta.IntegerField(default = 0)
    added = meta.DateTimeField('added', auto_now_add=True)

comment:3 Changed 12 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

I've verified that this works properly (with no error) using current post-magic-removal trunk.

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