I see. Thanks Madhan! A default value makes sense and addresses my usecase. Thanks, Fadi
On Fri, Nov 1, 2019 at 2:47 PM Madhan Neethiraj <[email protected]> wrote: > Hello Fadi, > > > > For primitive type attributes, a default value is assigned during entity > creation – irrespective of whether the attribute is optional or not. A > default value can be specified for an attribute in entity-def as shown > below: > > { > > "name": "TestEntity", > > "category": "ENTITY", > > "attributeDefs": [ > > { > > "name": "id", > > "typeName": "string", > > "isOptional": false > > }, > > { > > "name": "age", > > "typeName": "int", > > "isOptional": true, > > "defaultValue": -1, > > } > > ] > > } > > > > Having an option to not populate default value for optional attributes > will be useful. If this is critical for your usecase, can you please file a > JIRA? > > > > Thanks, > > Madhan > > > > *From: *Fadi Maali <[email protected]> > *Reply-To: *"[email protected]" <[email protected]> > *Date: *Thursday, October 31, 2019 at 4:16 AM > *To: *"[email protected]" <[email protected]> > *Subject: *missing numeric optional attribute is set to zero > > > > Hello, > > > > I created a type with one of the attributes of type int indicated as > optional. > > I then created an entity without supplying value for the optional > attribute. > > when I retrieve that entity, the value of the optional attribute is > actually zero. > > I expected the returned json to not include that attribute. > > > > Here is what I did: > > > > curl -X POST -u admin:admin -d '{"entityDefs":[{"name": "TestEntity", > "category": "ENTITY","attributeDefs": [{"name": "id","typeName": > "string","isOptional": false},{"name": "age","typeName": > "int","isOptional": true}]}]}' -H "Content-Type: application/json" > http://localhost:21000/api/atlas/v2/types/typedefs > <http://localhost:21000/api/atlas/v2/types/typedefs> > > > curl -X POST -u admin:admin -d '{"entities" : [{"typeName": > "TestEntity","attributes": {"id": "123"}}]}' -H "Content-Type: > application/json" http://localhost:21000/api/atlas/v2/entity/bulk > <http://localhost:21000/api/atlas/v2/entity/bulk> > > > curl -u admin:admin > http://localhost:21000/api/atlas/v2/entity/guid/48d6f3e8-0133-4ce2-b408-74df73bbb376 > <http://localhost:21000/api/atlas/v2/entity/guid/48d6f3e8-0133-4ce2-b408-74df73bbb376> > > {"referredEntities":{},"entity":{"typeName":"TestEntity","attributes":{"id":"123","age":0},"guid":"48d6f3e8-0133-4ce2-b408-74df73bbb376","status":"ACTIVE","createdBy":"admin","updatedBy":"admin","createTime":1572518090211,"updateTime":1572518090211,"version":0}} > > > > Thanks, > > Fadi >
