Opened 19 years ago

Closed 19 years ago

Last modified 18 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: no UI/UX: no

Description

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\base.py", line 64, in get_response
    response = callback(request, **param_dict)

  File "i:\projects\grono2\contrib\web\create_update.py", line 51, in create_object
    new_object = manipulator.save(new_data)

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

  File "d:\django\django\core\meta\__init__.py", line 1483, in manipulator_save
    was_changed = getattr(new_object, 'set_%s' % f.name)(new_data.getlist(f.name))

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

  File "d:\django\django\core\meta\__init__.py", 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 by Adrian Holovaty, 19 years ago

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 by wojtek3@…, 19 years ago

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 by Adrian Holovaty, 19 years ago

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