Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#5780 closed (fixed)

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

Reported by: Honza_Kral Owned by: brosner
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_Kral 6 years ago.
5780-against-7875.patch (2.0 KB) - added by Honza_Kral 6 years ago.
5780-against-7925.patch (2.0 KB) - added by jakub_vysoky 6 years ago.

Download all attachments as: .zip

Change History (16)

Changed 6 years ago by Honza_Kral

comment:1 Changed 6 years ago by jkocherhans

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 6 years ago by brosner

  • 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 6 years ago by garcia_marc

  • milestone set to 1.0 alpha

Changed 6 years ago by Honza_Kral

comment:4 Changed 6 years ago by Honza_Kral

  • Keywords ep2008 added

comment:5 Changed 6 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 follow-up: Changed 6 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 6 years ago by 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?

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 ; follow-up: Changed 6 years ago by 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

Changed 6 years ago by jakub_vysoky

comment:9 in reply to: ↑ 8 Changed 6 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 6 years ago by brosner

  • Keywords nfa-blocker removed
  • milestone changed from 1.0 alpha to 1.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 6 years ago by brosner

  • Owner changed from nobody to brosner
  • Status changed from new to assigned

comment:12 Changed 6 years ago by brosner

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in [8273].

comment:13 Changed 3 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.