8000 DISCUSSION: Test to show the issue with using model.save() without update_fields by boxed · Pull Request #322 · iommirocks/iommi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

DISCUSSION: Test to show the issue with using model.save() without update_fields #322

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 acco 8000 unt related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

boxed
Copy link
Collaborator
@boxed boxed commented Oct 26, 2022

For example, I have a Task model used for scheduling. This has some fields that should not be edited by the user, like last_checked that is used for a heartbeat, or a shutdown_command field that is used during deploy to tell the old job to gracefully shut down. If I edit the other fields of this Task in the admin, those other fields are also written, potentially overwriting data at crucial times if I'm very unlucky.

@jlubcke
Copy link
Collaborator
jlubcke commented Oct 26, 2022

One approach I have seen in another place is to have an additional column on tables and incrementing that value on each modification of a row. Then that value can be sent along with the form as a hidden field and in the save step be verified that no other modification has been made since the form was rendered. We could add support in iommi to at least help with implementing something like that.

@boxed
Copy link
Collaborator Author
boxed commented Oct 26, 2022

That's a slightly different thing I think. You could imagine a situation where the version number updates so often that the user can never save if it uses that approaching, while at the same time the admin interface only touches columns that are never updated by that other process. This is coincidentally my situation right now :)

@jlubcke
Copy link
Collaborator
jlubcke commented Oct 26, 2022

A more hacky fix could be to somehow calculate a default approximation to updated_fields and then have the possibility to add to that as a user.

@boxed
Copy link
Collaborator Author
boxed commented Oct 26, 2022

Yea, I was thinking to add all attr values in all fields to update_fields and then expose form.update_fields so if you go outside the attrs of fields, you have to add stuff there manually. That's strictly a breaking change, although I don't know if anyone uses the blanket save...

@boxed
Copy link
Collaborator Author
boxed commented Oct 31, 2022

This is handled by #325

@boxed boxed closed this Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0