Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alenzeinolov opened this issue Jan 16, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@alenzeinolov
Copy link

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

@alenzeinolov alenzeinolov changed the title Submit line actions are executed before inline formsets are saved fix: submit line actions are executed before inline formsets are saved Jan 16, 2025
@lukasvinclav lukasvinclav added the enhancement New feature or request label Jan 22, 2025
@lukasvinclav
Copy link
Contributor

lukasvinclav commented Jan 22, 2025

I believe this is a duplicate of #355. If you prepare a PR with a test. I will be happy to look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants