Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • cubicweb cubicweb
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 194
    • Issues 194
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • cubicweb
  • cubicwebcubicweb
  • Issues
  • #482

Closed
Open
Created Dec 09, 2021 by Nicola Spanti@nspantiMaintainer

Raw unique exception of RDBMS API on cardinality violation on update

When on an entity type of the schema, cardinality is defined with ? (0 or 1), and that the constraint is violated, we would except a RQL/YAMS/CubicWeb error and RDBMS depend one. Moreover the exception should be raised on commit and not on cw_set.

Example

Schema

class Group(EntityType):
    units = SubjectRelation('GroupItem, cardinality='+?')

Automatic test

def test_group_unit_multiple_update(self):
    with self.admin_access.cnx() as cnx:
        group = self.create_group(cnx, production_units=(self.item1_eid,))
        self.create_group(cnx, units=(self.item1_eid,))
        cnx.commit()
        with self.assertRaises(ValidationError) as error:  # FAIL
            group.cw_set(units=(self.item1_eid,self.item2_eid))
        # No need of cnx.commit() to have an exception raised!

Result

  • sqlite3.IntegrityError: UNIQUE constraint failed: production_units_relation.eid_from, production_units_relation.eid_to
  • psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "key_f98727f7a350360b2799dbd8b8f066a0"
    DETAIL:  Key (eid_from, eid_to)=(9070, 9053) already exists.

Versions used

  • CubicWeb 3.32.7
  • RQL 0.37.0
  • YAMS 0.45.3
Edited Dec 09, 2021 by Nicola Spanti
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking