j2labs/dictshield — Issue #23: id fields don't subclass correctly
Author: j2labs
Created: 2011-10-28 23:59:39+00:00
State: open

The following code does not honor the id field via subclassing. Comment or uncomment the id field in `SalesShipment` in the code snippet below to demonstrate the bug.

#!/usr/bin/env python

from dictshield.base import ShieldException
from dictshield.document import Document
from dictshield.fields import (URLField,
DateTimeField,
FloatField,
StringField)

class BaseRepresentation(Document):
id = URLField(required=True)
createdAt = DateTimeField(required=True)
updatedAt = DateTimeField(required=True)

class SalesShipment(BaseRepresentation):
id = URLField(required=True)
cost = FloatField(required=True, min_value=0)
currency = StringField(required=True)

data = {
"id" : "http://localhost:8080/sales-shipments/21e5bde8-f7e9-11e0-be50-0800200c9a66",
"currency" : "GBP",
"updatedAt" : "2011-10-28T19:39:22.783271",
"createdAt" : "2011-10-11T08:39:30",
"cost" : 0.92
}

shipment = SalesShipment(**data)
try:
shipment.validate()
except ShieldException, se:
print 'ShieldException caught: %s' % se

print "This shipment cost %f %s" % (shipment.cost, shipment.currency)