Custom attributes in Gramps 6.0

I noticed a possibly interesting thing in Gramps 6.0. Since Python is a very dynamic language any code can create new attributes in existing objects. If a new attribute is created in a Gramps object (e.g. Person object) then this attribute is also stored in the database along with other attributes. Assuming the object is added or committed to the database.

Note that this is about “Python level attributes” - not the Attributes that Gramps defines and that can be seen in the Attributes tab. Such a Python attribute is not visible in the regular Gramps interface but an addon could possibly use the attribute for some purpose.

For example, with SuperTool it is easy to demonstrate this. Run this script in the People category for a sample person (id=‘I0001’):

Then you can see the attribute in the database:

Note that there is also the attribute “commit_ok” which was automatically set by SuperTool.

This SuperTool script will verify that the attribute can also be read from the database:

It did not work this way in earlier Gramps versions (5.x). I noticed this because one of my addons (generatecitations) fails in 6.0 because of this feature.

Is this an intentional feature? Has this been discussed before?

Are you committing changes to the database? I don’t see how such changes could make it to the database without a commit. So, no, not intentional.

Yes, I am committing. The first Supertool script uses the “Commit changes” checkbox.

What handles person.my_attribute = "my value"? If it is a new DataDict object, then you can probably work around the issue by using:

person._my_attribute = "my value"

Supertool executes the statement with exec - where person refers to a gramps.gen.lib.Person object read from the database. Then it commits basically with db.commit_person(person, trans). So nothing unusual there.

I tried to demonstrate this also with Gram.py but got an error I couldn’t resolve.

But thanks for the tip. Using a leading underscore will probably help with the issue in ‘generatecitations’!