CMDBuild Forum

Problem chaging class attribute data type length

Hi all,

I'm changing through Administration Module a Class attribute data type from STRING (250) to STRING (1000).

No errors are shown in the GUI or the cmdbuild log:

INFO  2018-10-22 14:38:54 [jsonrpc ] Calling url /schema/modclass/saveattribute

INFO  2018-10-22 14:38:54 [cmdbuild] creating or updating attribute 'Attribute[name=Description,description=Description,ownerName=api_catalog,ownerNamespace=<null>,group=,fkDestinationName=,type=org.cmdbuild.dao.entrytype.attributetype.StringAttributeType@77172a0e,defaultValue=<null>,mode=WRITE,index=-1,classOrder=0,editorType=,filter=,metadata={},conditions=[ACTIVE, DISPLAYABLE_IN_LIST]]'

INFO  2018-10-22 14:38:54 [cmdbuild] checking common pre-conditions

INFO  2018-10-22 14:38:54 [cmdbuild] checking specific pre-conditions

INFO  2018-10-22 14:38:54 [cmdbuild] attribute already created, updating existing one

INFO  2018-10-22 14:38:54 [ddsql   ] SELECT * FROM cm_modify_attribute('"api_catalog"'::regclass,'Description','varchar(1000)',null,false,false,ARRAY[]::text[],ARRAY[]::text[]);

INFO  2018-10-22 14:38:54 [cmdbuild] checking post-conditions

INFO  2018-10-22 14:38:54 [cmdbuild] setting metadata for attribute 'Description'

INFO  2018-10-22 14:38:54 [jsonrpc ] Calling url /schema/modclass/getattributelist

INFO  2018-10-22 14:38:54 [cmdbuild] getting all-in-one 'interface org.cmdbuild.services.event.Observer'

 
But when I check the database, I see that it is still STRING (250):
 
cmdbuild=# \d+ api_catalog;
                                                                                                            Table "public.api_catalog"
     Column      |            Type             |             Modifiers              | Storage  | Stats target |                                                            Description
-----------------+-----------------------------+------------------------------------+----------+--------------+------------------------------------------------------------------------------------------------------------------------------------
 Id              | integer                     | not null default _cm_new_card_id() | plain    |              | MODE: reserved
 IdClass         | regclass                    | not null                           | plain    |              | MODE: reserved
 Code            | character varying(100)      |                                    | extended |              | MODE: read|DESCR: Code|INDEX: 1|BASEDSP: true|STATUS: active|GROUP:
 Description     | character varying(250)      |                                    | extended |              | MODE: read|DESCR: Description|INDEX: 2|BASEDSP: true|GROUP:
 
When I try to add a new card via API or GUI, I get:
Caused by: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; ERROR: value too long for type character varying(250); nested exception is org.postgresql.util.PSQLException: ERROR: value too long for type character varying(250)

Anyone knows why is this happening?
 
Thanks a bunch
Alexandre Juma
The "Description" attribute is inherited from a system class from which all the classes of a CMDBuild data model are inherited.
The error depends on the fact that it is not possible to modify an inherited attribute.
Unfortunately due to a bug the GUI of the CMDBuild Administration Module allows modification and does not report the error.
CMDBuild Team.
Hi,
 
Thanks for the reply.
 
Would it be a problem to change the data type directly in the DB?
 
Or do i need to recreate the class and repopulate it?
 
Thanks
Alexandre Juma
 
Previously Tecnoteca wrote:
The "Description" attribute is inherited from a system class from which all the classes of a CMDBuild data model are inherited.
The error depends on the fact that it is not possible to modify an inherited attribute.
Unfortunately due to a bug the GUI of the CMDBuild Administration Module allows modification and does not report the error.
CMDBuild Team.

 

You can not
delete the main class because it is a system class not visible in the
GUI, and in any case it would delete all the CI hierarchy.

You can change the length directly in the DB but there may be dependencies on other objects in the DB (views or other) and if performed incorrectly it can be a risky operation for the consistency of the database.
CMDBuild Team

 

 

Hi,
 
So my plan is to:
1) Create a new attribute costum_description on all classes with the correct data type lenght
2) Batch update all cards to copy Description content to costum_description
3) Turn the inherited Description attribute to Inactive
4) Change application code to stop using Description and start using costum_description
 
Nevertheless, maybe it's something you add to the roadmap. People who are not familiar  with the software will start leveraging heavily on this inherited field from master class and then run into these sort of problems.
 
Thanks for the precious help
 
BR
Alexandre Juma
 
Previously Tecnoteca wrote:
You can not delete the main class because it is a system class not visible in the GUI, and in any case it would delete all the CI hierarchy.
You can change the length directly in the DB but there may be dependencies on other objects in the DB (views or other) and if performed incorrectly it can be a risky operation for the consistency of the database.
CMDBuild Team