cubicweb #3096634 SQLGenobjectstore and size constraints [open]

The SQLGenobjectstore does not check the size constraints, which may lead to an error in copyfrom/executemany.

Moreover, the _import_statements should raise an Error, not print "Error in import statements".

The size constraints could be checked easily with this code:

def get_size_constraints(schema):
  """analyzes yams ``schema`` and returns the list of size constraints.

  The returned value is a dictionnary mapping entity types to a
  sub-dictionnaries mapping attribute names -> max size.
  size_constraints = {}
  # iterates on all entity types
  for eschema in schema.entities():
      # for each entity type, iterates on attribute definitions
      size_constraints[eschema.type] = eschema_constraints = {}
      for rschema, aschema in eschema.attribute_definitions():
          # for each attribute, if a size constraint is found,
          # append it to the size constraint list
          maxsize = None
          rdef = rschema.rdef(eschema, aschema)
          for constraint in rdef.constraints:
              if isinstance(constraint, SizeConstraint):
                  maxsize = constraint.max
                  eschema_constraints[rschema.type] = maxsize
  return size_constraints

 def apply_size_constraints(self, etype, kwargs):
      """ Apply the size constraints for a given etype, attribute and value
      size_constraints = self.size_constraints[etype]
      for attr, value in kwargs.items():
          if value:
              maxsize = size_constraints.get(attr)
              if maxsize is not None and len(value) > maxsize:
                  kwargs[attr] = value[:maxsize-4] + '...'
      return kwargs
done in<not specified>
closed by<not specified>