Skip to content

fix: submit line actions are executed before inline formsets are saved #973

@alenzeinolov

Description

@alenzeinolov

What version of Unfold are you using?
0.44.0

What version of Django are you using?
5.1

What browser are you using?
Not browser related

Did you checked changelog/commit history, if the bug is not already fixed?
Yes

Did you searched other issues, if the bug is not already fixed?
Yes

Did you checked documentation?
Yes

Are you able to replicate the bug in the demo site?
No, only usage of submit line actions I found was here https://demo.unfoldadmin.com/en/admin/formula/constructor/33/change/, but this admin page does not have any inlines.

Describe your issue
It seems that due to the nature that submit line actions are executed when model is saved, but before inline forms were saved, it's impossible to specify an action that for example will use both the main model, and it's children, as children data is not saved yet.

For example in my use case I had main model as read only page, and user needed to edit inline admin models in another tab, after editing I wanted to save & send API request to another server with new data entered in model inlines. However in my testing I found out that inline data was empty, at the time when I tried to initiate API request, but was saved after submit line action was executed. It happens only for the first time when data is empty, second time it will work, but I assume it would use old data, not the one that was submitted last.

I checked underlying django code for this, I assume the reason could be that submit line actions are happening in save_model method which saves only the main model, Django invokes another save_related method which saves additional formset data. It seems that in order for this to work properly, submit line actions should execute after both save_model and save_related methods have been executed.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions