Exactly! Here is Claude Code’s plan (I’d put this in Github discussions but it was never enabled):
Gramps ID Overflow — Investigation & Plan
Background
Each Gramps object has an ID like "P00023". The number of digits and leading zeros
is controlled by a config setting (e.g., preferences.iprefix = "I%04d"). When a
database grows large enough that the numeric portion overflows the format width (e.g.,
"I%04d" % 10000 silently produces "I10000"), the IDs go out of order and the user
must run Reorder Gramps IDs to fix them.
The goal is to detect this overflow and show a non-disruptive warning with a link to
the Reorder IDs dialog — without interrupting imports or data entry.
Current State (from code investigation)
ID format config keys
| Object |
Config key |
Default |
Index field |
| Person |
preferences.iprefix |
I%04d |
pmap_index |
| Place |
preferences.pprefix |
P%04d |
lmap_index |
| Event |
preferences.eprefix |
E%04d |
emap_index |
| Media |
preferences.oprefix |
O%04d |
omap_index |
| Citation |
preferences.cprefix |
C%04d |
cmap_index |
| Source |
preferences.sprefix |
S%04d |
smap_index |
| Family |
preferences.fprefix |
F%04d |
fmap_index |
| Repository |
preferences.rprefix |
R%04d |
rmap_index |
| Note |
preferences.nprefix |
N%04d |
nmap_index |
Key files
- ID generation:
gramps/gen/db/generic.py:1194 — _find_next_gramps_id()
- Format validation:
gramps/gen/db/generic.py:1027 — _validated_id_prefix()
- Format→closure:
gramps/gen/db/generic.py:1042 — __id2user_format()
- Regex:
r"(.*)%[0 ](\d+)[diu]$" — only matches zero-padded formats
- If no width specifier, closure just passes ID through unchanged
- Reorder tool:
gramps/plugins/tool/reorderids.py
- Regex:
r"(^[^\d]*)%(0[3-9])d([^\d]*$)" — requires 3–9 digit zero-padded format
- Already detects overflow internally (
index > index_max) but never surfaces it
- There is commented-out overflow detection code at
generic.py:1057–1065
Current overflow behavior
_find_next_gramps_id() uses Python’s % operator which silently expands past the
format width: "I%04d" % 10000 → "I10000". No warning is emitted. This happens
identically whether the record was created via the UI, an import, or any other path.
Plan
Constraint: never interrupt an import or data entry
The approach is:
- Compute overflow on the fly from data already in memory — no metadata storage needed.
- Show a non-modal warning bar in the main window, with a button to open Reorder IDs.
Step 1 — Overflow check helper on the db class
File: gramps/gen/db/generic.py
Add a method get_id_overflow_types() that iterates the 9 (prefix_fmt, map_index)
pairs and returns the set of object type names where the index has exceeded the format’s
maximum value.
The check for each object type is simply:
# e.g. for "I%04d", width=4, max=9999
if map_index > 10 ** width - 1:
overflowed.add(object_name)
Only applies when the format contains a fixed-width specifier (%0Nd). If the format
has no width (e.g., "P%d"), skip it — there is no fixed maximum to overflow.
No writes to the database, no metadata flags, no startup scan. The result is always
computed fresh from the current in-memory state.
Step 2 — Warning bar in the main window
File: gramps/gui/mainwin.py (or equivalent)
Connect to the database-changed signal. After the database loads, call
db.get_id_overflow_types(). If non-empty, show a non-modal Gtk.InfoBar at the
top of the content area:
Some Gramps IDs have exceeded their format width (Persons, Families).
[Reorder Gramps IDs]
The button fires the existing Reorder IDs tool directly. The bar is dismissible and
recomputed on every database-changed event — so it disappears automatically after a
successful reorder without any explicit “clear” call.
Because the check is based on the current map_index values (which are updated on
every write), this works for overflow caused by normal data entry, imports, or any
other source.
Step 3 (future / optional) — Dynamic format widening
Longer term: when overflow is detected, automatically promote the format from %04d
to %05d (or wider) and update the config. This changes user-visible behavior and
affects exports and merges, so it warrants a separate discussion and should not be
bundled with the warning feature.
Edge cases
Custom prefix formats
- Custom prefix, standard width — e.g.,
"FAM-%04d" → fully supported; overflow
check works the same way on the numeric portion.
- No width specifier — e.g.,
"P%d". The ID grows unboundedly by design.
__id2user_format’s regex won’t match, and the Reorder tool falls back to defaults.
No overflow concept applies; skip these object types in the check.
- Manually entered IDs — e.g., user types
"Smith-001" directly. These are stored
as-is; _find_next_gramps_id is not involved. Out of scope for this feature.
Warning precision
When the format has a known width, the warning message should be specific:
Person IDs have exceeded the 4-digit format (I%04d). Run Reorder Gramps IDs to fix.
Files to touch
| File |
Change |
gramps/gen/db/generic.py |
Add get_id_overflow_types() helper method |
gramps/gui/mainwin.py (or equivalent) |
Show Gtk.InfoBar warning with Reorder IDs button when overflow detected |