# Narrative Web Report Error cannot access local variable 'bletter' where it is not associated with a value

**URL:** <https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428>\
**Category:** Help\
**Created:** [April 10, 2025, 7:41pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428 "2025-04-10T19:41:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 10, 2025, 7:41pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/1 "2025-04-10T19:41:06Z")

</div>

Got the following error anybody got any ideas as to where I should look to find out the cause suspect something in my tree not a bug  
phil

```python
62156: ERROR: _reportdialog.py: line 801: Failed to run report.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gramps/gui/plug/report/_reportdialog.py", line 760, in report
    my_report.write_report()
  File "/usr/lib/python3/dist-packages/gramps/plugins/webreport/narrativeweb.py", line 538, in write_report
    self.tab["Person"].display_pages(the_lang, the_title)
  File "/usr/lib/python3/dist-packages/gramps/plugins/webreport/person.py", line 181, in display_pages
    self.individuallistpage(
  File "/usr/lib/python3/dist-packages/gramps/plugins/webreport/person.py", line 557, in individuallistpage
    max_rows = max_letter_rows[bletter]
                               ^^^^^^^
UnboundLocalError: cannot access local variable 'bletter' where it is not associated with a value

```

GRAMPS: 5.2.4  
Python: 3.11.2  
BSDDB: 6.2.9 (5, 3, 28)  
sqlite: 3.40.1 (2.6.0)  
LANG: en\_GB.UTF-8  
OS: Linux  
Distribution: 6.1.0-30-amd64

---

<div class="post-metadata">

**Author:** ![Nick-Hall](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/nick-hall/32/95_2.png) [@Nick-Hall](https://gramps.discourse.group/u/Nick-Hall)\
**Post date:** [April 10, 2025, 7:57pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/2 "2025-04-10T19:57:47Z")

</div>

It looks like this may be related to pull request [#1896](https://github.com/gramps-project/gramps/pull/1896) - “New indexes for big databases in the narrative web report”.

---

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 10, 2025, 8:23pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/3 "2025-04-10T20:23:04Z")

</div>

Thanks Nick

My Family Tree is approx 18000 individuals, tried increasing the value  
for the index from 500 to 2000 made no difference.  
Will spend some more time on this and get back to you  
phil

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [April 11, 2025, 9:07am UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/4 "2025-04-11T09:07:31Z")

</div>

Make a bug request for this problem.

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [April 11, 2025, 9:13am UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/5 "2025-04-11T09:13:10Z")

</div>

We have a problem here. Did you modified the sources ?

The following instruction does not exist at line 557:

```python
max_rows = max_letter_rows[bletter]

```

---

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 11, 2025, 9:56am UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/6 "2025-04-11T09:56:52Z")

</div>

Serge

I run 2 PC’s a Pi5 running Bookworm and an i5 running LMDE6 both have  
Version 5.2.4 with your mod for incl roles.  
Both do have that line as described at line 557.  
Neither has been updated or changed in the last 3 months.

I have subsequently run the report on the Pi using a simplified tree  
with no problem.

I need to retrace all my steps to reproduce the error will get back to you  
phil

---

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 13, 2025, 9:58am UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/7 "2025-04-13T09:58:02Z")

</div>

Serge

Apologies for delayed response.  
My usual working method is to create a backup on my LMDE PC and store it  
on my NAS, I then import it to my Pi5.  
For some reason (senior moment) I had copied my grampsdb folder on my  
LMDE PC and then pasted this into my Pi5. It is this version that brings  
up the error. So must be the difference in setup between LMDE and  
Bookworm that causes the issue which I have no inclination or desire to  
investigate further.  
Please do not worry about this further made a note to self only do the  
“import” in future.  
phil

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [April 13, 2025, 10:10am UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/8 "2025-04-13T10:10:01Z")

</div>

You should apply a patch for this. It was commit [a8885d5855d901f833064d1b69ec45f7b8cfe79d](https://github.com/gramps-project/gramps/commit/a8885d5855d901f833064d1b69ec45f7b8cfe79d)

---

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 13, 2025, 4:05pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/9 "2025-04-13T16:05:12Z")

</div>

Two problems with that commit for me

1. It is for Ver 6 not explicitly for 5.2.4  
2)“Fix narrative web report crash with empty an database.” My database is fully functional and not empty as far as I am aware  
phil

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [April 13, 2025, 4:21pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/10 "2025-04-13T16:21:44Z")

</div>

> [@comeng](#):
>
> It is for Ver 6 not explicitly for 5.2.4

This is the solution for you. You must adapt this patch to 5.2.4.

---

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 13, 2025, 6:30pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/11 "2025-04-13T18:30:41Z")

</div>

I am feeling particularly dense today but could you point me in the direction of the original report that caused you to make this patch.  
The fault occurred as a result of my own actions of copying and pasting a database rather than importing and when using the importing route I do not have an error, but the copying and pasting route gives an error however this database is perfectly usable other than for the Narrative Web Report.  
Thank you for confirming that the patch is suitable for 5.2.4  
phil

---

<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:** [April 13, 2025, 6:47pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/12 "2025-04-13T18:47:19Z")

</div>

Tye linked commit above says that it was merged into the 6.0 (for rc2) maintenance branch in February 2025:

- [PR1951](https://github.com/gramps-project/gramps/pull/1951) Narrative web: crash with empty database.

In response to:

- [13619](https://gramps-project.org/bugs/view.php?id=13619): Error message when creating a narrative web report

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [April 13, 2025, 6:56pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/13 "2025-04-13T18:56:28Z")

</div>

This was one way to create the bug.  
I can say you can safely apply the patch I proposed.  
This patch only remove the max\_rows variable which is the cause of your problem.  
You can see what it do with the command:  
`git show a8885d5855d901f833064d1b69ec45f7b8cfe79d`

---

<div class="post-metadata">

**Author:** ![comeng](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@comeng](https://gramps.discourse.group/u/comeng)\
**Post date:** [April 15, 2025, 12:40pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/14 "2025-04-15T12:40:17Z")

</div>

I think I would like to close this off. Firstly by thanking Serge, Nick  
and Brian for their assistance/forbearance for trying to resolve a  
situation of my own creation (should have known better).  
The current situation is that I have applied Serge’s latest commit with  
no issues on existing or imported databases.  
The database I copied and pasted now does not show an error when running  
as expected but the final report has no contents whatsoever yet the db  
is clearly populated.  
phil

---

<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:** [May 15, 2025, 12:40pm UTC](https://gramps.discourse.group/t/narrative-web-report-error-cannot-access-local-variable-bletter-where-it-is-not-associated-with-a-value/7428/15 "2025-05-15T12:40:55Z")

</div>

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