Monday, October 5, 2015

We are having a UnicodeError (#570) when trying to print an isip.Contract:

Error while evaluating the expression "table(rt.modules.isip.DelegatedTasksByContract.request(obj))" defined in the "from" part of a statement. UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
File "<string>", line 1, in <module>
File "/lino/lino/modlib/appypod/", line 245, in insert_table
return self.insert_table_(*args, **kw)
File "/lino/lino/modlib/appypod/", line 482, in insert_table_
return toxml(table)
File "/lino/lino/utils/", line 86, in toxml
return buf.getvalue()
File "/usr/lib/python2.7/", line 271, in getvalue
self.buf += ''.join(self.buflist)
<type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)

More precisely this occurs when rendering DelegatedTasksByContract (and a similar message comes for EventsByContract) into the document.

As a first step I would like to reproduce these. Which turns out to not be trivial.

I cannot “just print” an ISIP contract (or any lino.modlib.excerpts.mixins.Certifiable) in a tested document because “printing” actually creates an excerpt object, i.e. modifies the database.

Two possible approaches: (1) generate more excerpts as part of initdb_demo and/or (2) run above test as a Django test in a temporary database.

(1) means a subtle change in lino.modlib.excerpts.fixtures.demo2 which until now generated one excerpt per ExcertType (and even this only when it had not yet been done). Now I added a global variable PRINT_THEM_ALL: the new default behaviour is to print them all.

When PRINT_THEM_ALL is True, the initdb_demo takes ages:

$ time fab initdb
real        12m26.660s
user        8m14.219s
sys 1m4.190s

But it helped to identify some minor bugs in templates that failed when certain fields are empty. Before adapting the test suite to this, I’d like to meditate about how necessary this option is and how configurable it should be.

A side effect: The virtual field client on the Guest model for Lino Welfare is now defined on the model instead of injecting it in lino_welfare.modlib.reception. I tend to recommend model subclassing over inject_field when possible.

I started to write an introduction to virtual fields in the Developer’s Guide.