Commits

Leonard Ritter  committed 5148c61

* datenwerk schema: fixed defaultkey() not returning newly created property

  • Participants
  • Parent commits 948dbba

Comments (0)

Files changed (2)

File include/datenwerkpp/templates.hpp

 		T property = get_key<T>(item, key);
 		if (!property.c_ptr()) {
 			clear(item, key);
-			item.set_key(key, wrap(defvalue));
+			property = wrap(defvalue);
+			item.set_key(key, property);
 		}
 		return property;
 	}
 		Array property = get_key<Array>(item, key);
 		if (!property.c_ptr()) {
 			clear(item, key);
-			item.set_key(key, Object());
+			property = Array();
+			item.set_key(key, property);
 		}
 		return property;
 	}

File python/datenwerk/schema/python.py

             CLS_NAME = self.cls.name,
             DECL_NAME = self.decl.name,
             NAME = self.name,
+            CAST_WRAPPER = '',
         )
 
     @classmethod
         self.k.update(dict(
             DWK_CLS = 'dw.Object',
             DEFAULT = 'None',
+            CAST_WRAPPER = '$DECL_NAME.cast',
         ))
 
     def write_impl(self, writer):
         self.write_clear_impl(writer)
         writer.write(self('def get_$NAME(self):\n')) 
         writer.inc()
-        writer.write(self('return $DECL_NAME.cast(impl.get_key($DWK_CLS, self, "$NAME"))\n'))
+        writer.write(self('return $CAST_WRAPPER(impl.get_key($DWK_CLS, self, "$NAME"))\n'))
         writer.dec(); writer.write('\n')
         
         writer.write(self('def set_$NAME(self, value):\n')) 
         self.k.update(dict(
             DWK_CLS = 'dw.Array',
             ITEM_CLS = item_acc('$DWK_CLS'),
-            ITEM_CLS_NAME = item_acc('$DECL_NAME'),
             DEFAULT = item_acc('$DEFAULT'),
+            ITEM_CAST_WRAPPER = item_acc('$CAST_WRAPPER'),
         ))
 
     def write_impl(self, writer):
         
         writer.write(self('def $NAME(self, index):\n'))
         writer.inc()
-        writer.write(self('return $ITEM_CLS_NAME.cast(impl.get_element_value($ITEM_CLS, self, "$NAME", index, $DEFAULT))\n'))
+        writer.write(self('return $ITEM_CAST_WRAPPER(impl.get_element_value($ITEM_CLS, self, "$NAME", index, $DEFAULT))\n'))
         writer.dec(); writer.write('\n')
         
         writer.write(self('def add_$NAME(self, value):\n'))
         item_acc = Accessor.get(self.cls, self.name, self.decl.items) 
         self.k.update(dict(
             DWK_CLS = 'dw.Link',
-            ITEM_CLS_NAME = item_acc('$DECL_NAME'),
             DEFAULT = 'None',
+            ITEM_CAST_WRAPPER = item_acc('$CAST_WRAPPER'),
         ))
     
     def write_impl(self, writer):
         
         writer.write(self('def get_$NAME(self):\n')) 
         writer.inc()
-        writer.write(self('return $ITEM_CLS_NAME.cast(impl.get_value($DWK_CLS, self, "$NAME", $DEFAULT))\n'))
+        writer.write(self('return $ITEM_CAST_WRAPPER(impl.get_value($DWK_CLS, self, "$NAME", $DEFAULT))\n'))
         writer.dec(); writer.write('\n')
         
         writer.write(self('def set_$NAME(self, value):\n')) 
     writer.write(k('class $NAME(impl.SchemaItem):\n'))
     writer.inc()
 
-    # write accessor implementations
-    for name,prop in decl.properties.iteritems():
-        writer.write('# ' + name + '\n')
-        accessor = Accessor.get(decl, name, prop)
-        accessor.write_impl(writer)
-        writer.write('\n')
+    if not decl.properties:
+        writer.write('pass\n')
+    else:
+        # write accessor implementations
+        for name,prop in decl.properties.iteritems():
+            writer.write('# ' + name + '\n')
+            accessor = Accessor.get(decl, name, prop)
+            accessor.write_impl(writer)
+            writer.write('\n')
     writer.dec()
     writer.write('\n')