@@ -145,7 +145,7 @@ func createAttributeValueSql(
145145 value ,
146146 metadata ,
147147 ).
148- Suffix ("RETURNING id" ).
148+ Suffix (createSuffix ).
149149 ToSql ()
150150}
151151
@@ -162,14 +162,15 @@ func (c PolicyDBClient) CreateAttributeValue(ctx context.Context, attributeID st
162162 value ,
163163 metadataJSON ,
164164 )
165+
165166 if err != nil {
166167 return nil , err
167168 }
168169
169170 var id string
170171 if r , err := c .QueryRow (ctx , sql , args ); err != nil {
171172 return nil , err
172- } else if err := r .Scan (& id ); err != nil {
173+ } else if err := r .Scan (& id , & metadataJSON ); err != nil {
173174 return nil , db .WrapIfKnownInvalidQueryErr (err )
174175 }
175176
@@ -194,6 +195,10 @@ func (c PolicyDBClient) CreateAttributeValue(ctx context.Context, attributeID st
194195 members = append (members , attr )
195196 }
196197
198+ if err = unmarshalMetadata (metadataJSON , metadata ); err != nil {
199+ return nil , err
200+ }
201+
197202 // Update FQN
198203 c .upsertAttrFqn (ctx , attrFqnUpsertOptions {valueId : id })
199204
@@ -216,7 +221,7 @@ func getAttributeValueSql(id string, opts attributeValueSelectOptions) (string,
216221 "'value', vmv.value, " +
217222 "'active', vmv.active, " +
218223 "'members', vmv.members || ARRAY[]::UUID[], " +
219- getMetadataField ("vmv" , true ) +
224+ constructMetadata ("vmv" , true ) +
220225 "'attribute', JSON_BUILD_OBJECT(" +
221226 "'id', vmv.attribute_definition_id )"
222227 if opts .withFqn {
@@ -228,7 +233,7 @@ func getAttributeValueSql(id string, opts attributeValueSelectOptions) (string,
228233 "av.value" ,
229234 "av.active" ,
230235 members ,
231- getMetadataField ("av" , false ),
236+ constructMetadata ("av" , false ),
232237 "av.attribute_definition_id" ,
233238 }
234239 if opts .withFqn {
@@ -281,7 +286,7 @@ func listAttributeValuesSql(attribute_id string, opts attributeValueSelectOption
281286 "'value', vmv.value, " +
282287 "'active', vmv.active, " +
283288 "'members', vmv.members || ARRAY[]::UUID[], " +
284- getMetadataField ("vmv" , true ) +
289+ constructMetadata ("vmv" , true ) +
285290 "'attribute', JSON_BUILD_OBJECT(" +
286291 "'id', vmv.attribute_definition_id )"
287292 if opts .withFqn {
@@ -293,7 +298,7 @@ func listAttributeValuesSql(attribute_id string, opts attributeValueSelectOption
293298 "av.value" ,
294299 "av.active" ,
295300 members ,
296- getMetadataField ("av" , false ),
301+ constructMetadata ("av" , false ),
297302 "av.attribute_definition_id" ,
298303 }
299304 if opts .withFqn {
@@ -352,7 +357,7 @@ func listAllAttributeValuesSql(opts attributeValueSelectOptions) (string, []inte
352357 "'value', vmv.value, " +
353358 "'active', vmv.active, " +
354359 "'members', vmv.members || ARRAY[]::UUID[], " +
355- getMetadataField ("vmv" , true ) +
360+ constructMetadata ("vmv" , true ) +
356361 "'attribute', JSON_BUILD_OBJECT(" +
357362 "'id', vmv.attribute_definition_id )"
358363 if opts .withFqn {
@@ -364,7 +369,7 @@ func listAllAttributeValuesSql(opts attributeValueSelectOptions) (string, []inte
364369 "av.value" ,
365370 "av.active" ,
366371 members ,
367- getMetadataField ("av" , false ),
372+ constructMetadata ("av" , false ),
368373 "av.attribute_definition_id" ,
369374 }
370375 if opts .withFqn {
0 commit comments