[referencer] A question about document types and document.get_field()

Christopher Belanger chris.belanger at utoronto.ca
Wed Dec 21 14:40:55 EST 2011

> I assume you're writing the plugin in Python?
Thanks for the quick reply!  It's in Python, yes.  I am strictly a
novice/hobbyist programmer, so I really appreciate that Referencer is
relatively easy to extend like this.

>> The problem is that if it tries to get a field that doesn't
>> exist, rather than just returning a null value for that field, it
>> throws
>> an exception and the plugin doesn't return anything at all. 
> I'm not intimately familiar with this part, but in Python you can catch
> exceptions as in:
> try:
> 	title = doc.get_field("title")
> except:
> 	title = ""
Thanks, I didn't know about that!  That may work, but it would require 
doing a check like that for every single doc.get_field.  It seems like
it would be easier and probably more efficient to have it handled in the
source code by having the object return a null result to the plugin if
the field doesn't exist.  This is, in fact, what it says will happen in
the "Writing Plugins for Referencer" document, so the fact that this
does not occur--and that it instead throws an exception that crashes the
plugin--probably qualifies as a bug.

I've made an (extremely simple!) modification to the source that causes
doc.get_field to act as the documentation says it should, which in turn
allows my plugin to run.  Is there a way for me to submit the patch
generated by mercurial for consideration?  The change is trivial, but as
a non-programmer, submitting a patch to an open-source project would be

After looking more closely at PythonDocument.C, I see that there is no
command available to the plugin to determine the document type.  This is
too bad, because it would make citation formatting a snap.

 - Chris

More information about the referencer mailing list