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

Duplicated entity created even when errors occur #268

Open
marcantoinedupre opened this issue Mar 28, 2023 · 0 comments
Open

Duplicated entity created even when errors occur #268

marcantoinedupre opened this issue Mar 28, 2023 · 0 comments
Labels

Comments

@marcantoinedupre
Copy link
Contributor

La copie de l'entité dupliquée est créée même quand le processus rencontre des erreurs.

Le code actuel de rollback de la transaction ne fonctionne pas car les savepoints n'ont pas d'effet en fonctionnement normal avec autocommit = on.

    def duplicate(self, **kwargs):
        if not self.can_duplicate:
            return None
        sid = transaction.savepoint()
        try:
	    [...]
            transaction.savepoint_commit(sid)
        except Exception as exc:
            transaction.savepoint_rollback(sid)
            raise exc
        return clone

Proposition de code de rollback fonctionnel :

    def duplicate(self, **kwargs):
        if not self.can_duplicate:
            return None
        try:
            with transaction.atomic():
	        [...]
        except Exception as exc:
            # améliorer le traitement de l'exception ici
            raise exc
        return clone

Il faudrait ajouter un test fonctionnel sur ce point.

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

No branches or pull requests

1 participant