# Gramps asks if "Save changes" for people who modified via supertool

**URL:** <https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206>\
**Category:** Help\
**Tags:** third-party-addon, supertool-script\
**Created:** [October 9, 2024, 7:34pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206 "2024-10-09T19:34:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 9, 2024, 7:34pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/1 "2024-10-09T19:34:37Z")

</div>

How can I modify supertool script to avoid a problem:

When I open modified person and then close it, I am asked I I want save changes. Looks like person has some flag which indicates that person was changed, right?

```python
[initial_statements]
...
def execute():
...
        if str(primary_surname.get_origintype()).startswith('Taken'):
            print(f"Person. {gramps_id} (female) has 'Taken' as primary surname: '{primary_surname.get_surname()}'")
            
            alt_name = Name()
            alt_name.set_first_name(nameobj.get_first_name())
            alt_name.set_surname_list([primary_surname])
            alt_name.set_type(NameType.MARRIED)
            obj.add_alternate_name(alt_name)
            
            filtered_surnames = [s for s in nameobj.get_surname_list() if not str(s.get_origintype()).startswith('Taken')]
            nameobj.set_surname_list(filtered_surnames)
            nameobj.set_type(NameType.BIRTH)
            
            # Commit the changes
            db.commit_person(obj, trans)
...

[statements]
execute()

[filter]

[expressions]

[scope]
all

[unwind_lists]
False

[commit_changes]
False

[summary_only]
True

```

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [October 9, 2024, 8:27pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/2 "2024-10-09T20:27:38Z")

</div>

“Commit changes” should be ‘True’

---

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 10, 2024, 4:52am UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/3 "2024-10-10T04:52:10Z")

</div>

but in this case all my DB people are updated even if no changes there, just Last Changed date become the same for all them. This is not very good. Is it possible to aboid this negative effect?

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [October 10, 2024, 5:23am UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/4 "2024-10-10T05:23:57Z")

</div>

You probably don’t want the scope to be ‘all’.

It is more reasonable that it would be at least filtered (only Females with other filter criteria) or (more likely) selected persons.

 ![image](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/b/b842924509c3a431b51bbb2eedca90fee09c7c5f.png)

---

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 10, 2024, 6:59am UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/5 "2024-10-10T06:59:02Z")

</div>

Got it. But this is strange a bit. These sscripts update people and dont require save updates in the interface [Supertool script to move surnames with "Patronymic" type to given names](https://gramps.discourse.group/t/supertool-script-to-move-surnames-with-patronymic-type-to-given-names/5888)  
But this script requires save changes in UI:

```python
            myobj = obj
            new_name = Name()
            new_name.set_first_name("Maria Antonivna")
            new_name.set_surname_list([])
            new_name.set_type(NameType.BIRTH)
            myobj.set_primary_name(new_name)

            db.commit_person(myobj, trans)

```

Where is differense?

---

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 10, 2024, 7:01am UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/6 "2024-10-10T07:01:35Z")

</div>

I remember abybody said that we need work via objects like myobj, and dont use obj directly. But I use it. Looks like I do something wrong

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [October 10, 2024, 1:46pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/7 "2024-10-10T13:46:06Z")

</div>

I didn’t validate the code. Just addressed the question asked about committing changes.

But it appears to set values blindly. So I was assuming that you were filtering to the people where the action is appropriate from outside the script. (Manually or with a series of filters.)

A deeper explanation from Perplexity in response to the prompt:

> As an expert in Gramps software, including its source code, Python, database design, SQLite, and the SuperTool add-on, please explain how SuperTool uses “proxy objects” to temporarily hold changes before they are committed to the tree database. Additionally, discuss why using a `db.commit_person(obj, trans)` command in a SuperTool script might be appropriate or inappropriate concerning the functionality of the “commit changes” option in the GUI.

In Gramps’ SuperTool, **proxy objects** are used to represent internal objects temporarily. These proxy objects allow users to manipulate data without directly altering the main database. This design ensures that changes are only finalized when the user selects the “commit changes” option, providing a safe way to experiment with modifications[2].

Including a `db.commit_person(obj, trans)` command in a SuperTool script bypasses this safeguard by directly committing changes to the database. This can be inappropriate if it conflicts with the user’s intention to review and confirm changes through the GUI’s “commit changes” option, potentially leading to unintended data alterations.

Citations:  
[1] [What Are Proxy Objects - Win32 apps | Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/winauto/what-are-proxy-objects)  
[2] [isotammi-addons/source/SuperTool/README.md at master · Taapeli/isotammi-addons · GitHub](https://github.com/Taapeli/isotammi-addons/blob/master/source/SuperTool/README.md)  
[3] [Proxy Windows Tooling via SOCKS. Leveraging SOCKS to proxy tools from a… | by Nick Powers | Posts By SpecterOps Team Members](https://posts.specterops.io/proxy-windows-tooling-via-socks-c1af66daeef3?gi=a4dbd0d00b1a)  
[4] [JavaScript Proxy - 30 seconds of code](https://www.30secondsofcode.org/js/proxy/p/1/)  
[5] [SuperTools](https://learn.foundry.com/katana/content/tg/super_tools/super_tools.html)  
[6] [Creating commits only if changes present · octokit/octokit.js · Discussion #1938 · GitHub](https://github.com/octokit/octokit.js/discussions/1938)  
[7] [Writing a SuperTool](https://learn.foundry.com/katana/Content/ug/groups_macros_super_tools/writing_super_tool.html)  
[8] [Git - git-commit Documentation](https://git-scm.com/docs/git-commit)

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [October 10, 2024, 1:59pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/8 "2024-10-10T13:59:40Z")

</div>

Further…

The SuperTool’s “Commit Changes” functionality in Gramps does not perform a delta comparison between proxy objects and the main database. Instead, it commits all changes made to the processed objects in the current category when the “Commit Changes” checkbox is selected[1](https://github.com/Taapeli/isotammi-addons/blob/master/source/SuperTool/README.md). This approach means that any modifications made to proxy objects are applied directly to their corresponding internal Gramps objects without checking for differences. Thus, it commits changes more “blindly,” applying all modifications regardless of whether they alter the existing data or not.

---

<div class="post-metadata">

**Author:** ![kku](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@kku](https://gramps.discourse.group/u/kku)\
**Post date:** [October 12, 2024, 6:39pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/9 "2024-10-12T18:39:02Z")

</div>

This was a tricky one. It seems that Gramps requires the surname list to be non-empty. Replace the line

```
new_name.set_surname_list([])  

```

with

```
new_name.set_surname_list([Surname()])  

```

and try again.

---

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 12, 2024, 7:05pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/10 "2024-10-12T19:05:44Z")

</div>

> [@kku](#):
>
> It seems that Gramps requires the surname list to be non-empty. Replace the line

But in the first script version I also used non-empty:

```python
def execute():
...
        if str(primary_surname.get_origintype()).startswith('Taken'):
            print(f"Person. {gramps_id} (female) has 'Taken' as primary surname: '{primary_surname.get_surname()}'")
            
            alt_name = Name()
            alt_name.set_first_name(nameobj.get_first_name())
            alt_name.set_surname_list([primary_surname])

```

But anyway I had the same behaviour. I already executed the script, then opened all updated people and clicked Save for all them. Anyway this is much more faster than edit 1300 females manually. Totally I saved about 5 hours of 7.5 hours. But if you know more ideas I will be glad hear them to avoid this trouble in the future. Thanks!

---

<div class="post-metadata">

**Author:** ![kku](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@kku](https://gramps.discourse.group/u/kku)\
**Post date:** [October 12, 2024, 7:15pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/11 "2024-10-12T19:15:54Z")

</div>

Maybe the reason is that there is also this line:

```
nameobj.set_surname_list(filtered_surnames)

```

and the “filtered\_surnames” list could be empty?

---

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 12, 2024, 7:18pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/12 "2024-10-12T19:18:53Z")

</div>

@kku and a question or maybe for future improvement… Is it possible dont apply “commit” option for entities (e.g. for people), what were not changed? Does it make sense? I undersand that I can filter all them via filter, but I dont know how make for example the above changes via proxies, but I can use this documentation to make everything what I need [The gramps.gen.lib Module — Gramps 5.1.0 documentation](https://gramps-project.org/api_5_1_x/gen/gen_lib.html)  
But if I dont use proxy, commits checkbot doesnt work.

---

<div class="post-metadata">

**Author:** ![kku](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@kku](https://gramps.discourse.group/u/kku)\
**Post date:** [October 12, 2024, 7:21pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/13 "2024-10-12T19:21:28Z")

</div>

Good question. I have not thought about that. Will investigate.

---

<div class="post-metadata">

**Author:** ![Urchello](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@Urchello](https://gramps.discourse.group/u/Urchello)\
**Post date:** [October 12, 2024, 7:34pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/14 "2024-10-12T19:34:39Z")

</div>

> [@kku](#):
>
> and the “filtered\_surnames” list could be empty?

Hm, you are right…

```python
filtered_surnames = [s for s in nameobj.get_surname_list() if not str(s.get_origintype()).startswith('Taken')]

```

All these 1300 females had “Married” type as primary with one Surname only. And I changed “Married” type to “Birth” type and moved that only one surname to alternate names. So in all 100% items my filtered\_surnames were empty. I understoot it later when logged it. Look like I should find a way just clear surnames list for “Birth” type?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/2ac1e712b7adf612e31ca08a55419f4cf37c0158.png) [@system](https://gramps.discourse.group/u/system)\
**Post date:** [November 11, 2024, 7:35pm UTC](https://gramps.discourse.group/t/gramps-asks-if-save-changes-for-people-who-modified-via-supertool/6206/15 "2024-11-11T19:35:17Z")

</div>

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