[Fixed] Bug when inserting a row into spreadsheet

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
wang02139
Posts: 11
Joined: Sun Sep 06, 2020 10:28 pm

[Fixed] Bug when inserting a row into spreadsheet

Postby wang02139 » Sun Sep 06, 2020 10:41 pm

When a spreadsheet has entries with aliases which goes through 2 levels of reference, and the user inserts a row, the reference is broken and there is an error that a property is not found.

I have attached a very simple file with this problem. If you insert a row at, say, row 3, there is an error

"15:19:52 <Spreadsheet> Cell.cpp(594): Unnamed#Spreadsheet.A9: Property 'b' not found in 'b'"

There are 2 aliases:
a = 1
b = a + 1
The last cell is b+1 which has the error.


OS: Ubuntu 18.04.5 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22284 (Git) AppImage
Build type: Release
Branch: master
Hash: bf1e8e48389f5e9e25bd77b67fe98da4213e797c
Python version: 3.8.5
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)
Attachments
spreadsheet_insert.FCStd
(1.79 KiB) Downloaded 2 times
Last edited by wang02139 on Sun Sep 13, 2020 2:52 pm, edited 1 time in total.
chrisb
Posts: 26920
Joined: Tue Mar 17, 2015 9:14 am

Re: Bug when inserting a row into spreadsheet

Postby chrisb » Sun Sep 06, 2020 11:05 pm

This was reported recently.
wang02139
Posts: 11
Joined: Sun Sep 06, 2020 10:28 pm

Re: Bug when inserting a row into spreadsheet

Postby wang02139 » Sun Sep 06, 2020 11:39 pm

Thanks. Can you point me to the discussion in the forum or bug tracker?
TheMarkster
Posts: 1904
Joined: Thu Apr 05, 2018 1:53 am

Re: Bug when inserting a row into spreadsheet

Postby TheMarkster » Mon Sep 07, 2020 12:10 am

Refreshing fixes it for me.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
wang02139
Posts: 11
Joined: Sun Sep 06, 2020 10:28 pm

Re: Bug when inserting a row into spreadsheet

Postby wang02139 » Mon Sep 07, 2020 12:16 am

We still want to file and fix the bug, right?
TheMarkster
Posts: 1904
Joined: Thu Apr 05, 2018 1:53 am

Re: Bug when inserting a row into spreadsheet

Postby TheMarkster » Mon Sep 07, 2020 3:23 am

I looked through the source code, but I can't figure out what the problem is. I can call a recompute to fix it and suppress the exception message, but that's really more of a hack than an actual fix. I'm not sure if it's worth submitting as a PR. Thoughts?
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
wang02139
Posts: 11
Joined: Sun Sep 06, 2020 10:28 pm

Re: Bug when inserting a row into spreadsheet

Postby wang02139 » Mon Sep 07, 2020 3:46 am

This bug is quite bad. I have a large spreadsheet with lots of parameters. When I insert a row, I was badly surprised that many cells have errors like this. Most users wouldn't know to refresh to work around this bug.

I also don't think recompute is the right way to fix it. Maybe the cells should be updated in a correct order. Let's file a bug report first. I'll also look at the spreadsheet code to see how to fix it.
chrisb
Posts: 26920
Joined: Tue Mar 17, 2015 9:14 am

Re: Bug when inserting a row into spreadsheet

Postby chrisb » Mon Sep 07, 2020 5:29 am

Searching for "Spreadsheet insert row bug" shows this as the first(!) result: https://forum.freecadweb.org/viewtopic.php?t=49969. The usual procedure here is to prepare things in a discussion as good as possible before creating a ticket.
wang02139
Posts: 11
Joined: Sun Sep 06, 2020 10:28 pm

Re: Bug when inserting a row into spreadsheet

Postby wang02139 » Mon Sep 07, 2020 6:33 am

OK. I'll be more careful next time.

I looked at the code and understood the problem now:

Here it's using revAliasProp to look for the location, but it's the old location of the alias:
https://github.com/FreeCAD/FreeCAD/blob ... t.cpp#L993

The alias may be changed later in moveCell which updates revAliasProp
https://github.com/FreeCAD/FreeCAD/blob ... t.cpp#L708

Thus the dependency graph is wrong. It's not an easy fix. I'll think of a clean way to fix it.