Projet

Général

Profil

Development #41342

IntegrityError sur import de rôles

Ajouté par Frédéric Péters il y a environ 4 ans. Mis à jour il y a environ 4 ans.

Statut:
Fermé
Priorité:
Normal
Assigné à:
Catégorie:
-
Version cible:
-
Début:
06 avril 2020
Echéance:
% réalisé:

0%

Temps estimé:
Patch proposed:
Oui
Planning:
Non

Description

Export d'un export de rôles de recette, import sur une prod,

IntegrityError at /manage/site-import/
duplicate key value violates unique constraint "a2_rbac_role_name_unique_idx_0" 
DETAIL:  Key (name, ou_id)=(Debug & Support Entr'ouvert, 1) already exists.

Dans l'export,

            "name": "Debug & Support Entr'ouvert", 
            "slug": "debug-eo", 

mais ce rôle existe déjà sur la production, avec un autre slug,

            "name": "Debug & Support Entr'ouvert", 
            "slug": "debug-support-entrouvert", 

(et il y a un rôle "Debug EO" qui a le slug "debug-eo").

Il faudrait que l'erreur soit remontée de manière intelligible.


Fichiers

0002-tests-remove-unused-variable-41342.patch (887 octets) 0002-tests-remove-unused-variable-41342.patch Benjamin Dauvergne, 09 avril 2020 17:04
0001-data_transfer-validate-uniqueness-of-roles-41342.patch (4,51 ko) 0001-data_transfer-validate-uniqueness-of-roles-41342.patch Benjamin Dauvergne, 09 avril 2020 17:04
Firefox_Screenshot_2020-04-09T15-03-55.736Z.png (14,7 ko) Firefox_Screenshot_2020-04-09T15-03-55.736Z.png Benjamin Dauvergne, 09 avril 2020 17:05
0002-tests-remove-unused-variable-41342.patch (887 octets) 0002-tests-remove-unused-variable-41342.patch Benjamin Dauvergne, 09 avril 2020 17:37
0001-data_transfer-validate-uniqueness-of-roles-41342.patch (4,53 ko) 0001-data_transfer-validate-uniqueness-of-roles-41342.patch Benjamin Dauvergne, 09 avril 2020 17:37
0002-tests-remove-unused-variable-41342.patch (887 octets) 0002-tests-remove-unused-variable-41342.patch Benjamin Dauvergne, 10 avril 2020 15:25
0001-data_transfer-validate-uniqueness-of-roles-41342.patch (15,1 ko) 0001-data_transfer-validate-uniqueness-of-roles-41342.patch Benjamin Dauvergne, 10 avril 2020 15:25
0001-utils-add-a-lazy_join-function-41342.patch (2,8 ko) 0001-utils-add-a-lazy_join-function-41342.patch Benjamin Dauvergne, 15 avril 2020 11:42
0002-data_transfer-use-ValidationError-instead-of-DataImp.patch (12,1 ko) 0002-data_transfer-use-ValidationError-instead-of-DataImp.patch Benjamin Dauvergne, 15 avril 2020 11:42
0003-data_transfer-validate-models-before-updating-creati.patch (3,36 ko) 0003-data_transfer-validate-models-before-updating-creati.patch Benjamin Dauvergne, 15 avril 2020 11:42
0004-tests-remove-unused-variable-41342.patch (887 octets) 0004-tests-remove-unused-variable-41342.patch Benjamin Dauvergne, 15 avril 2020 11:42

Révisions associées

Révision 7b8ed451 (diff)
Ajouté par Benjamin Dauvergne il y a environ 4 ans

utils: add a lazy_join function (#41342)

Use it to join translated strings.

Révision 8f5aadf8 (diff)
Ajouté par Benjamin Dauvergne il y a environ 4 ans

data_transfer: use ValidationError instead of DataImportError (#41342)

Révision 52ab85eb (diff)
Ajouté par Benjamin Dauvergne il y a environ 4 ans

data_transfer: validate models before updating/creating them (#41342)

To prevent collision between roles when altering their name and their
slug is already unique. Ex.:

R1(slug=a, name=A) import> R1(slug=a, name=B)
R2(slug=b, name=B)

Révision 30439cad (diff)
Ajouté par Benjamin Dauvergne il y a environ 4 ans

tests: remove unused variable (#41342)

Révision 673557b3 (diff)
Ajouté par Benjamin Dauvergne il y a environ 4 ans

misc: move lazy_label in a2.utils.lazy (#41342)

Révision 1b6a8561 (diff)
Ajouté par Benjamin Dauvergne il y a environ 4 ans

misc: clean dead imports (#41342)

Historique

#2

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

  • Assigné à mis à Benjamin Dauvergne
#3

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

C'est pas magnifique mais ça fait le job.

#4

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

Ça affichera suffisamment d'information pour trouver l'origine du problème (voir screenshot, on a le type, l'attribut et la valeur concerné, et le souci).

#6

Mis à jour par Paul Marillonnet il y a environ 4 ans

Je pense que la logique derrière le bout de code

if e.args and isinstance(e.args[0], ValidationError): […] else: […]

devrait être prise en charge dans une méthode magique DataImportError.__str__ nouvellement définie et non pas à l'impromptu dans la méthode SiteImportView.form_valid.

#8

Mis à jour par Paul Marillonnet il y a environ 4 ans

  • Je pense que ce serait plus clair en proposant un premier patch qui abandonne DataImportError.
  • Pourquoi défaire la listcomp (ligne 310 de data_transfer.py) ?
  • Je pense qu'on peut mettre la création de authentic2.utils.lazy dans un patch à part, en profitant pour y inclure le décorateur authentic2.utils.lazy_label et en faisant les corrections d'import.
#9

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

Paul Marillonnet a écrit :

  • Pourquoi défaire la listcomp (ligne 310 de data_transfer.py) ?

Pas très lisible.

#11

Mis à jour par Paul Marillonnet il y a environ 4 ans

  • Statut changé de Solution proposée à Solution validée

À toi de voir mais je continue de penser qu'il faudrait déplacer le lazy_label déjà existant dans le module authentic2.utils.lazy nouvellement créé. Sinon à part ça, ack.

#12

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

  • Statut changé de Solution validée à Résolu (à déployer)
commit 1b6a8561eee1007a5b39d2dc1daf9e704209794a
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Thu Apr 16 12:35:23 2020 +0200

    misc: clean dead imports (#41342)

commit 673557b3015d48861d2e8ff45555cb0fb057c477
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Thu Apr 16 12:35:04 2020 +0200

    misc: move lazy_label in a2.utils.lazy (#41342)

commit 30439cada09bccf098f251c9f6d53e0f2dab48c2
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Thu Apr 9 16:14:50 2020 +0200

    tests: remove unused variable (#41342)

commit 52ab85eb5b87b2723e7d9c6fb70d692334e96da5
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Wed Apr 15 11:29:21 2020 +0200

    data_transfer: validate models before updating/creating them (#41342)

    To prevent collision between roles when altering their name and their
    slug is already unique. Ex.:

       R1(slug=a, name=A) -import-> R1(slug=a, name=B)
       R2(slug=b, name=B)

commit 8f5aadf89fbc0544f1de94825ced8e03467ae1d3
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Thu Apr 9 16:15:20 2020 +0200

    data_transfer: use ValidationError instead of DataImportError (#41342)

commit 7b8ed451807b4d038d80c4fbb420df798deac6c2
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Wed Apr 15 11:25:24 2020 +0200

    utils: add a lazy_join function (#41342)

    Use it to join translated strings.
#13

Mis à jour par Frédéric Péters il y a environ 4 ans

  • Statut changé de Résolu (à déployer) à Solution déployée

Formats disponibles : Atom PDF