I have declared a table as
db.define_table("agencies",
Field("hotel", "reference hotels", notnull=True),
Field("subgroup", "reference subgroups", label="Subgroup"),
Field("agency", "string", length=100, writable= False, label="Agency", notnull=True),
Field("alias", "string"),
Field("commission", "double"),
auth.signature
)
At the controller:
frm2 = SQLFORM(db.agencies, formstyle="rows").process(formname="agencies")
if frm2.accepted:
dd("All good")
elif frm2.errors:
dd(frm2.errors)
dd is a print to browser and stop execution function, not related.
request.post_vars:
<Storage {
'agency': 'My Cool Agency'
, 'modified_by': '2'
, 'alias': ''
, 'hotel': '7'
, 'is_active': ''
, 'created_by': '1'
, 'id': '1'
, 'commission': ''
, 'created_on': '2016-03-31 14:47:34'
, 'modified_on': '2016-04-01 17:25:32'
, '_formkey': 'beee6ee6-d9d4-4de9-85c5-b248cb5f6f20'
, '_formname': 'agencies'
, 'subgroup': '43'}>
i get this frm2.errors:
<Storage {'hotel': 'no data'}>
hotel is a referenced field and it has a value of 7 on the request.post_vars
inspecting sqlhtml.py accepts function, line 1673:
elif field.default is None and field.type != 'blob':
self.errors[fieldname] = 'no data'
self.accepted = False
return False
value = fields.get(fieldname, None)
if field.type == 'list:string':
if not isinstance(value, (tuple, list)):
fields[fieldname] = value and [value] or []
elif isinstance(field.type, str) and field.type.startswith('list:'):
if not isinstance(value, list):
fields[fieldname] = [safe_int(
x) for x in (value and [value] or [])]
elif field.type == 'integer':
if value is not None:
fields[fieldname] = safe_int(value)
elif field.type.startswith('reference'):
## Avoid "constraint violation" exception when you have a
## optional reference field without the dropdown in form. I.e.,
## a field with code to be typed, in a data-entry form.
the reference field is falling in
elif field.default is None and field.type != 'blob':
instead
elif field.type.startswith('reference'):
why field.default is None returns True?
Tried this in the controller:
print db.agencies.hotel.default == ""
True
print db.agencies.hotel.default is not None
False
This case should not fall into field.default is None
Thanks