Opened 9 years ago

Closed 8 years ago

Last modified 5 years ago

#5780 closed (fixed)

pass the created/updated object to formsets in edit_inline for validation

Reported by: Honza Král Owned by: Brian Rosner
Component: contrib.admin Version: newforms-admin
Severity: Keywords: ep2008
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When validating InlineFormset it is essential that you have access to the created/updated object. I created a patch that handles exactly that - it creates the object (without saving it) and passes it to the FormSet.

Attachments (3)

5780.diff (1.7 KB) - added by Honza Král 9 years ago.
5780-against-7875.patch (2.0 KB) - added by Honza Král 8 years ago.
5780-against-7925.patch (2.0 KB) - added by jakub_vysoky 8 years ago.

Download all attachments as: .zip

Change History (16)

Changed 9 years ago by Honza Král

Attachment: 5780.diff added

comment:1 Changed 9 years ago by jkocherhans

Triage Stage: UnreviewedAccepted

Sounds reasonable. I'll take this into account when I'm rewriting the admin save code (which I'll need to do at some point.)

comment:2 Changed 9 years ago by Brian Rosner

Keywords: nfa-blocker added

Not sure if this is critical enough prior to a merge, but marking it nfa-blocker anyway. Joseph, please correct that if it can be deferred until later.

comment:3 Changed 8 years ago by Marc Garcia

milestone: 1.0 alpha

Changed 8 years ago by Honza Král

Attachment: 5780-against-7875.patch added

comment:4 Changed 8 years ago by Honza Král

Keywords: ep2008 added

comment:5 Changed 8 years ago by jakub_vysoky

there is problem with models.ImageField and this patch

=> file is saved twice on storage (one original name and one with underscore ;))

comment:6 Changed 8 years ago by jkocherhans

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

comment:7 Changed 8 years ago by Honza Král

Replying to jkocherhans:

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

Hi Joseph, the transaction thing should work for the main issue, but there is still the issue of some custom non db-related validation that could be done in formsets.

The object is saved in .save_add() and .save_change() - there is

new_object = form.save(commit=True)

I haven't touched that but we could pass in the obj as well and just call

obj.save()
form.save_m2m()

comment:8 in reply to:  6 ; Changed 8 years ago by Honza Král

Replying to jkocherhans:

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

I am the dense one here - the transaction-based approach would work (with no problems), if you are willing to sacrifice MySQL MyISAM to get there ;). That's your call

Changed 8 years ago by jakub_vysoky

Attachment: 5780-against-7925.patch added

comment:9 in reply to:  8 Changed 8 years ago by jkocherhans

Replying to Honza_Kral:

Replying to jkocherhans:

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

I am the dense one here - the transaction-based approach would work (with no problems), if you are willing to sacrifice MySQL MyISAM to get there ;). That's your call

Grrr... if only I had a time machine so I could go back and... No. I didn't think about that. It isn't an acceptable tradeoff. Damn my nice tools altering my perception of reality! :)

comment:10 Changed 8 years ago by Brian Rosner

Keywords: nfa-blocker removed
milestone: 1.0 alpha1.0 beta

Dropping nfa-blocker as this will be dealt with once merged with trunk. Also pushing to 1.0 beta since this will likely change the API it needs to be looked at pre-1.0. See http://groups.google.com/group/django-developers/browse_thread/thread/a2d8baf9b6846649

comment:11 Changed 8 years ago by Brian Rosner

Owner: changed from nobody to Brian Rosner
Status: newassigned

comment:12 Changed 8 years ago by Brian Rosner

Resolution: fixed
Status: assignedclosed

Fixed in [8273].

comment:13 Changed 5 years ago by Jacob

milestone: 1.0 beta

Milestone 1.0 beta deleted

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