Supertool. How add an existing note and date to an event?

I have a short question. What is wrong in my code fragment? It does not add the note. Commit checkbox is turned on.

note = db.get_note_from_gramps_id("N1823")
print(note.gramps_id, note.handle)

if (gramps_id == "I9968"):
    birth.obj.add_note(note.handle)

Screenshot from 2024-06-01 21-20-23

And also tried commit manually:

note = db.get_note_from_gramps_id("N1823")
print(note.gramps_id, note.handle)

if (gramps_id == "I9968"):
    birth.obj.add_note(note.handle)
    event_date = Date()
    event_date.set(
        modifier=Date.MOD_RANGE, 
        value=(0, 0, 1900, False, 0, 0, 1990, False)
    )
    birth.obj.set_date_object(event_date)
    db.commit_event(birth.obj, trans)
    birth._commit(db, trans)
    print("commited")

Still doesn’t work

The reason is explained in the SuperTool README:

https://github.com/Taapeli/isotammi-addons/blob/master/source/SuperTool/README.md#proxy-objects

Excerpt:

Proxy objects are created when they are needed. This means also that identical expressions do not always refer to the same objects.
For example, in People category, the expression birth.place.obj refers to a Gramps internal Place object. But if you use the same expression multiple times in the same query then each one will refer to a different Place object. This matters only if you intend to update the object - changes in one object will not be seen in the other and calling db.commit_place() would not have any effect. Solution is to save the object reference in a local variable, e.g.

# does not work:
birth.place.obj.set_latitude(90)
db.commit_place(birth.place.obj, trans)

# ok:
placeobj = birth.place.obj
placeobj.set_latitude(90)
db.commit_place(placeobj, trans)    

So you would have to do something like:

if (gramps_id == "I9968"):
    birth_obj = birth.obj
    birth_obj.add_note(note.handle)
    db.commit_event(birth_obj, trans)

So this is a flaw in the design of SuperTool. Sorry about that!

You need to commit explicitly because the “Commit changes” checkbox only affects the current category (i.e. Person objects in this case).

3 Likes

@kku It is working now. Beautiful!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.