Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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 203
    • Issues 203
    • 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
  • #454

Closed
Open
Created Nov 02, 2021 by Noé Gaumont@ngaumont🐙Maintainer

Validate arguments during entity creation

During entity creation, some argument are checked (in the yams way) and other are converted only during database insertion.

For example considering the following schema:

class Example(EntityType):
    a_time = TZDatetime()
    a_int = Int()

In the shell, one can create an entity with the following command:

import datetime as dt
create_entity('Example', a_time='2021-10-21', a_int='4')
create_entity('Example', a_time=dt.datetime.now(), a_int=4)

This works because there is some conversions in different module.

Conversion defined in YAMS

a_int is converted because:

  1. during the copy of edited a call is made to check in cubicweb.server.edition.
  2. This uses the underlying check function in yams.schema but this functions also convert the values.
  3. the convert values uses some converters defined here. If there is no converter, then the value is used as is.

The a_int conversion replaces the values used inside the glob_add_entity (and before any hook is called).

Conversion defined in logilab database

a_time is converted because:

  1. there is no conversion in yams
  2. during the glob_add_entity a call is made to source.add_entity
  3. during add_entity, a call is made to preprocess_entity. This functions returns processed arguments attrs but leave the entity not modified
  4. The preproccess_entity function use some converters to build the processed arguments. The converters are defined in logilab_database.
  5. the processed arguments are consumed in the sql argument but forgotten otherwise.

The correct value is inserted in the database, but the values inside entity in add_glob_entity are still string. This is problematic for dates for example.

The fix for this issue is the following MR in yams, but releasing yams seems complicated.

This is kinda related to !346 (merged)

Edited Nov 02, 2021 by Noé Gaumont
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking