-
Notifications
You must be signed in to change notification settings - Fork 40
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
(BSR)[API] feat: public api: add @atomic to products module #15082
base: master
Are you sure you want to change the base?
(BSR)[API] feat: public api: add @atomic to products module #15082
Conversation
4436206
to
5fb9f57
Compare
e1dc8fc
to
396df39
Compare
Visit the preview URL for this PR (updated for commit e6af3e8): https://pc-pro-testing--pr15082-jbaudet-2024-11-18-j-2nmsbk8c.web.app (expires Sat, 11 Jan 2025 16:14:12 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 032d233ee67e1c50d6af12e29c936c7076770eb1 |
396df39
to
4474a62
Compare
4474a62
to
30fcee6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revue partiel parce que c'est toujours les deux mêmes erreurs et si je continue je vais me répéter. Il y en a probablement d'autres similaire dans la suite
@@ -276,6 +281,7 @@ def _create_stock(product: offers_models.Offer, body: serialization.ProductOffer | |||
) | |||
), | |||
) | |||
@atomic() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cette fonction appeles indirectement create_stock
qui appele async_index_offer_ids
qui devrait être dans un on_commit
@@ -333,6 +339,7 @@ def post_product_offer(body: serialization.ProductOfferCreation) -> serializatio | |||
) | |||
), | |||
) | |||
@atomic() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_create_or_update_ean_offers.delay
devrait être dans un on_commit sinon on va avoir des problemes de concurrence et l'endpoint va parfois pas marcher (ce qui est assez difficile a débugger)
api/src/pcapi/core/offers/api.py
Outdated
@@ -443,9 +443,10 @@ def update_offer( | |||
withdrawal_updated = updates_set & withdrawal_fields | |||
oa_updated = "offererAddress" in updates | |||
if should_send_mail and (withdrawal_updated or oa_updated): | |||
transactional_mails.send_email_for_each_ongoing_booking(offer) | |||
on_commit(partial(transactional_mails.send_email_for_each_ongoing_booking, offer)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attention on ne peut pas passer des objets liés a la session (ici offer
) a des fonctions utilisées dans un on_commit parce que ces fonctions sont appelées après la fin de la session. Dans le meilleur des cas ça rajoute un appel a la db apres la session, dans le pire des cas ça plante.
(si tu as besoin d'aider pour migrer la fonction hésites pas a me ping)
|
||
reason = search.IndexationReason.OFFER_UPDATE | ||
|
||
search.async_index_offer_ids([offer.id], reason=reason, log_extra={"changes": updates_set}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
les appels asynchrones doivent être dans des on_commit
reason=search.IndexationReason.STOCK_CREATION, | ||
) | ||
|
||
search.async_index_offer_ids([offer.id], reason=search.IndexationReason.STOCK_CREATION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
api/src/pcapi/core/offers/api.py
Outdated
search.async_index_offer_ids( | ||
[stock.offerId], | ||
reason=search.IndexationReason.STOCK_DELETION, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
[offer.id], | ||
reason=search.IndexationReason.MEDIATION_CREATION, | ||
) | ||
search.async_index_offer_ids([offer.id], reason=search.IndexationReason.MEDIATION_CREATION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
api/src/pcapi/core/offers/api.py
Outdated
@@ -1037,10 +1034,17 @@ def _delete_stock(stock: models.Stock, author_id: int | None = None, user_connec | |||
) | |||
if cancelled_bookings: | |||
for booking in cancelled_bookings: | |||
transactional_mails.send_booking_cancellation_by_pro_to_beneficiary_email(booking) | |||
transactional_mails.send_booking_cancellation_confirmation_by_pro_email(cancelled_bookings) | |||
on_commit(partial(transactional_mails.send_booking_cancellation_by_pro_to_beneficiary_email, booking)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cette fonction (et spécifiquement celle ci) n'a pas besoin d'être dans un on_commit
api/src/pcapi/core/offers/api.py
Outdated
transactional_mails.send_booking_cancellation_confirmation_by_pro_email(cancelled_bookings) | ||
on_commit(partial(transactional_mails.send_booking_cancellation_by_pro_to_beneficiary_email, booking)) | ||
|
||
on_commit(partial(transactional_mails.send_booking_cancellation_confirmation_by_pro_email, cancelled_bookings)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cancelled_bookins ne peut pas êter passé a un on_commit :(
api/src/pcapi/core/offers/api.py
Outdated
else: | ||
if isinstance(offer, models.Offer): | ||
compliance.update_offer_compliance_score(offer, is_primary=False) | ||
on_commit(partial(compliance.update_offer_compliance_score, offer, is_primary=False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offer ne peut pas êter passé dans on_commit :(
Add @atomic to routes and some nested functions called by them.
30fcee6
to
e6af3e8
Compare
But de la pull request
Ajout du décorateur
@atomic
aux routes du moduleproducts
de l'API publique.Ces ajouts s'accompagnent d'autres :
on_commit
pour les fonctions appelées (in)directement par ces routes et qui nécessitent que la transaction soit validée avant de s'exécuter.