Skip to content

Unexpected insertion/update as multi property

I just noticed, that inserting a non-list property using a python-list will lead to a multi property being created:

import caosdb as db

# Insert data model:
rt = db.RecordType(name="TestBug")
p = db.Property(name="test_bug_property", datatype=db.INTEGER)
db.Container().extend([rt, p]).insert()

# Insert test record:
r = db.Record(name="TestRecord")
r.add_parent(rt)
r.add_property(p, value=18)
r.insert()

# Update the record:
test_r = db.Record(id=r.id, name="TestRecord")
test_r.add_parent(rt)
test_r.add_property(id=p.id, name="test_bug_property", value=[18, 12])
test_r.update()

Output on update:

<Record id="108" cuid="108--8703a6ee-3469-4897-bc06-19415e6a545b" name="TestRecord">
  <Version id="7441f4846e7962c9cd5b9e15a24eaebf6be7bb75" head="true">
    <Predecessor id="fadb123bb5ae274426b8d4a3a8575f5554a665b4"/>
  </Version>
  <Parent id="103" name="TestBug"/>
  <Property id="104" name="test_bug_property" datatype="INTEGER" importance="FIX" flag="inheritance:FIX">
    <Value>18</Value>
    <Value>12</Value>
    <Warning code="17" description="Property has no unit."/>
  </Property>
</Record>

Output on retrieve:

test_r = db.Record(name="TestRecord").retrieve()
print(test_r)
<Record id="108" name="TestRecord">
  <Version id="7441f4846e7962c9cd5b9e15a24eaebf6be7bb75" head="true">
    <Predecessor id="fadb123bb5ae274426b8d4a3a8575f5554a665b4"/>
  </Version>
  <noscript>
    </noscript>
  <Parent id="103" name="TestBug"/>
  <Property id="104" name="test_bug_property" datatype="INTEGER" importance="FIX" flag="inheritance:FIX">18</Property>
  <Property id="104" name="test_bug_property" datatype="INTEGER" importance="FIX" flag="inheritance:FIX">12</Property>
</Record>

At least for me that was highly unexpected behavior. I would have appreciated a warning/error, that the property to be set is not a LIST property.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information