imbajin commented on code in PR #3035:
URL: https://github.com/apache/hugegraph/pull/3035#discussion_r3328885596


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/PropertyKey.java:
##########
@@ -121,7 +121,12 @@ public void defineDefaultValue(Object value) {
 
     public Object defaultValue() {
         // TODO add a field default_value
-        return this.userdata().get(Userdata.DEFAULT_VALUE);
+        Object value = this.userdata().get(Userdata.DEFAULT_VALUE);
+        // Userdata is reloaded from JSON as a raw Map, so a typed default
+        // value (e.g. Date) comes back as a String. Normalize it to the
+        // runtime type expected by this property key's data type. Idempotent
+        // for values already of the expected type.
+        return value == null ? null : this.validValue(value);

Review Comment:
   ⚠️ **Preserve SET cardinality when normalizing defaults**
   
   `defaultValue()` now delegates `~default_value` normalization to 
`validValue()`, but JSON-reloaded SET defaults arrive as an `ArrayList`. The 
existing `convValue()` then chooses the output collection from the input type, 
so a `Cardinality.SET` default can still come back as an `ArrayList`. The new 
SET test only asserts `Collection`, so it misses this.
   
   This can install list-valued defaults for SET properties after schema 
reload, preserving duplicates and breaking cardinality semantics. Please make 
both core and struct `PropertyKey.convValue()` choose the target container from 
`this.cardinality` (`LinkedHashSet` for SET, `ArrayList` for LIST), and add a 
regression assertion that a SET default returns a `Set` and collapses 
duplicates.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to