Opened 18 years ago

Closed 16 years ago

#2724 closed defect (fixed)

edit_inline ... foreignkey(core=True) bug

Reported by: judgej@… Owned by: nobody
Component: contrib.admin Version: dev
Severity: normal Keywords: nfa-fixed edit_inline
Cc: gary.wilson@…, erob@…, jesse.lovelace@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Spent days fighting this, found lots of django-users and tickets somewhat associated. My solution found.

Example:
class Parent(models.Model):

name = models.CharField(maxlength=100
class Admin: pass

class Child(models.Model):

variable=models.CharField(maxlength=32)
value=models.IntegerField()
folks = models.ForeignKey(Parent, core=True, edit_line=models.Tabular)

Bug:
Django happy since you have a core=True in any child member.
DB tables get created fine.
Can create a Parent in the admin interface ... and stick in a couple children.
But ==> no children ever get saved.

Stick core=True in the other members, it still won't work.
You have to remove core=True in the ForeignKey() member.

Attachments (1)

fun_with_rel.diff (944 bytes ) - added by erob@… 18 years ago.
some fun with rel :)

Download all attachments as: .zip

Change History (18)

comment:1 by bangcok_dangerus (at) hotmail.com, 18 years ago

I've also encountered this problem.

As I see it, it doesn't make sense to have 'core=True' on the same field you've specified 'edit_inline=...' on. The value for this field is obviously automatically set to the id of the 'parent' related object. Specifying 'core=True' on the 'edit_inline=...' field makes the admin silenty throw away your form input and wrongly report that the parent object was successfully save/altered.

comment:2 by amcnabb@…, 18 years ago

I'm having the same problem with ForeignKey fields. Unfortunately, I can't work around the problem by removing core=True from all edit_inline objects. The model in question has three ForeignKey fields, all of which have core=True and edit_inline=True. There aren't any other fields that I can make "core", so the workaround here doesn't work.

So, somehow the inlined object needs to ignore the "core" property for the field that refers to the enclosing object. Does that make sense?

P.S. I can't figure out why the system thinks that this comment is spam.

comment:3 by Gary Wilson <gary.wilson@…>, 18 years ago

Cc: gary.wilson@… added

comment:4 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedAccepted
Version: SVN

Can someone build a test case/example of this to help us debug it?

comment:5 by erob@…, 18 years ago

Cc: erob@… added

Whats the error msg?
Here it says: TypeError: 'int' object is unsubscriptable.

Traceback (most recent call last):
File "/usr/local/users/erob/django/django/core/handlers/base.py" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "/usr/local/users/erob/django/django/contrib/admin/views/decorators.py" in _checklogin

  1. return view_func(request, *args, kwargs)

File "/usr/local/users/erob/django/django/views/decorators/cache.py" in _wrapped_view_func

  1. response = view_func(request, *args, kwargs)

File "/usr/local/users/erob/django/django/contrib/admin/views/main.py" in add_stage

  1. new_object = manipulator.save(new_data)

File "/usr/local/users/erob/django/django/db/models/manipulators.py" in save

  1. if f.core and not isinstance(f, FileField) and f.get_manipulator_new_data(rel_new_data, rel=True) in (None, ):

File "/usr/local/users/erob/django/django/db/models/fields/init.py" in get_manipulator_new_data

  1. return new_data.get(self.name, [self.get_default()])[0]

TypeError at /sysadmin/polls/poll/add/
'int' object is unsubscriptable

theres no core=True in the foreignkey... however its definitely not
the expected result. is that the same bug we're talking?

many thanks


by erob@…, 18 years ago

Attachment: fun_with_rel.diff added

some fun with rel :)

comment:6 by erob@…, 18 years ago

Has patch: set
Keywords: rel core=True edit_inline added
Needs documentation: set
Needs tests: set
Resolution: worksforme
Status: newclosed

Please tell me if that patch works for you.
It is working for me for using core=True on child members,
in a very simple Poll/Choice app:

Choice model:

class Choice(models.Model):
      poll   = models.ForeignKey(Poll, edit_inline=models.TABULAR, \
        max_num_in_admin=3, num_extra_on_change=0)
      choice = models.CharField(maxlength=200, core=True)
      votes  = models.IntegerField(core=True, default=0)
      def __str__(self):
          return self.choice
      class Admin:
            pass

As a work-around, apply the patch and use max_num_in_admin and num_extra_on_change
to see if it makes any differences.. It seems to break things without theses, but
with the following changes, it doesnt show any error while trying to add new polls
in the admin. As a side-note, I havent found good docs for the rel attribute,
what is this for anyway ??

comment:7 by Gary Wilson <gary.wilson@…>, 18 years ago

Resolution: worksforme
Status: closedreopened

comment:8 by Gary Wilson <gary.wilson@…>, 18 years ago

FYI, setting a ticket resolution as worksforme is not intended for specifying whether or not a patch works, but rather for indicating that the problem is not reproducible and is not a bug.

comment:9 by erob@…, 18 years ago

To Gary:

FYI, seriously, that is odd. But I dont want to impose to you a way
to think over another, so if you feel "worksforme" means whatever else,
then I'm happy with that.

On another side, it would have been great or perhaps
more informative to know if the patch works for you,
rather than 1) imposing your way of thinking to the others, 2)
not giving any helpful inputs related to this issue.

In the former case I would be happy to hear from you
again.

Thanks,
Etienne

in reply to:  9 comment:10 by James Bennett, 18 years ago

I don't think there's any "imposing" going on here, just an explanation of what we use the "worksforme" status for -- when we mark a bug "worksforme" it means "I tried to reproduce the bug and couldn't, please check your setup and see if it still happens". When there's a patch which fixes the bug, we leave it open until the patch gets committed into Django, so that we can make it work for everybody :)

comment:11 by erob@…, 18 years ago

... What does ubernostrum means anyway? ;-)

in reply to:  11 comment:12 by Simon G. <dev@…>, 18 years ago

Resolution: fixed
Status: reopenedclosed

Replying to erob@cpan.org:

... What does ubernostrum means anyway? ;-)

An extremely powerful medicine that cures all.

Reading the comments here, I think we need to clarify the docs regarding triage resolution states I've created #3658 to do this.

comment:13 by Simon G. <dev@…>, 18 years ago

Resolution: fixed
Status: closedreopened

in reply to:  8 comment:14 by anonymous, 18 years ago

Replying to Gary Wilson <gary.wilson@gmail.com>:

FYI, setting a ticket resolution as worksforme is not intended for specifying whether or not a patch works, but rather for indicating that the problem is not reproducible and is not a bug.

OK, I'll pay more attention to the triage states semantics next time.

Please accept my apologies.

Regards,
Etienne

comment:15 by anonymous, 18 years ago

Cc: jesse.lovelace@… added

comment:16 by Brian Rosner, 17 years ago

Keywords: nfa-fixed added; rel core=True removed

This is no longer a problem with newforms-admin. core=True usage is completely gone. Tagging with nfa-fixed to be closed when newforms-admin is merged.

comment:17 by Michael Newman, 16 years ago

Resolution: fixed
Status: reopenedclosed

I do believe the recent merge has fixed this issue.

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