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

change extra_data with atomic operations to reduce concurrent problems #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PetrDlouhy
Copy link
Owner

@PetrDlouhy PetrDlouhy commented Nov 22, 2024

Pokus o opravu https://github.com/BlenderKit/BlenderKit-server/issues/951

  • Je potřeba zkontrolovat, jestli se opravdu všechno správně uloží, jestli nebylo počítáno, že se něco uloží implicitně
  • Zatím to rozdrobuje historii změn - otázka, jestli je to dobře

@PetrDlouhy PetrDlouhy force-pushed the pr/atomic_changes branch 2 times, most recently from 10ee32d to 93fb86d Compare November 22, 2024 15:43
@@ -43,16 +43,20 @@


def add_extra_data(payment, new_extra_data):
payment.refresh_from_db()
Copy link
Contributor

@radekholy24 radekholy24 Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be better?

Suggested change
payment.refresh_from_db()
payment.refresh_from_db(fields=["extra_data"])

Just to make it more future-proof...



def add_new_status(payment, new_status):
payment.refresh_from_db()
Copy link
Contributor

@radekholy24 radekholy24 Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be better?

Suggested change
payment.refresh_from_db()
payment.refresh_from_db(fields=["extra_data"])

Just to make it more future-proof...

Comment on lines +68 to +70
payment._change_reason = 'PayU Payments: add_new_status' # For django-simple-history
payment.save(update_fields=["extra_data"])
payment._change_reason = None
Copy link
Contributor

@radekholy24 radekholy24 Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this (as well as in all the other cases) may be a bit safer:

Suggested change
payment._change_reason = 'PayU Payments: add_new_status' # For django-simple-history
payment.save(update_fields=["extra_data"])
payment._change_reason = None
payment._change_reason, payment_change_reason_original = 'PayU Payments: add_new_status', payment._change_reason # For django-simple-history
payment.save(update_fields=["extra_data"])
payment._change_reason = payment_change_reason_original

Or maybe

Suggested change
payment._change_reason = 'PayU Payments: add_new_status' # For django-simple-history
payment.save(update_fields=["extra_data"])
payment._change_reason = None
payment._change_reason = (payment._change_reason or '') + 'PayU Payments: add_new_status' # For django-simple-history
payment.save(update_fields=["extra_data"])
payment._change_reason = None

🤔

But I may be overengineering this...

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