Skip to content

Conversation

@justin2004
Copy link
Contributor

@justin2004 justin2004 commented Nov 17, 2025

i think we have a little bug wrt deferred modifications.

demonstration

put this in the CsvSheet class (just for this demo)

defer = True

currently we have this behavior:

vd sample_data/benchmark.csv
add-row
edit the customer column

Screenshot 2025-11-17 at 3 10 14 PM

then in the vd repl

vd.sheet.getDeferredChanges()
({140131282503616: [None, None, None, None, None, None, None]}, {}, {})

note that there is a deferred addition but has no column values (all None) even though we modified 1 cell.
that is, the deferred modifications are lost if applied to a new row.

with this PR we have this behavior:

vd sample_data/benchmark.csv
add-row

Screenshot 2025-11-17 at 3 12 58 PM

then confirm it is an empty row at the vd repl
vd.sheet.getDeferredChanges()
({139923036424208: [None, None, None, None, None, None, None]}, {}, {})

note empty row -- as expected

now edit the name column and another column if you like

Screenshot 2025-11-17 at 3 14 21 PM

and at the vd repl
vd.sheet.getDeferredChanges()
({139923036424208: [None, 'fred', None, 'chickpea', None, None, None]}, {}, {})

note that the deferred addition now includes all modifications -- so we effectively rolled the modifications into the addition (since it was a deferred addition anyway)

@justin2004 justin2004 marked this pull request as ready for review November 17, 2025 21:36
@justin2004
Copy link
Contributor Author

justin2004 commented Nov 18, 2025

just to note the reason...

i am extending the Imap loader to support sending emails (with smtp) and using deferred changes is useful for that:

image

@saulpw
Copy link
Owner

saulpw commented Nov 19, 2025

Hm, I thought this is how it already worked. When I view a sqlite database with --debug (which shows the SQL statements executed), do a similar set of add/edit commands and then commit, it only shows the one INSERT, and no UPDATEs. Are there different code paths on this for some reason?

@justin2004
Copy link
Contributor Author

justin2004 commented Nov 20, 2025

hey @saulpw , i think i see what is happening.

since the deferred mods don't get added to the deferred adds (in the develop branch -- like my example above shows)
the sqlite loader, upon commit, when it has a deferred add has to reach back into the sheet to get the values itself using:
col.getTypedValue(row) or col.getDisplayValue(r)

notice how the parameters to the execute sql function are built by calling 2 helper functions that reach back into the sheet (instead of using the values in the deferred adds (because they get discarded if done after the initial add-row command)).

i think i can simplify the sqlite loader on top of this PR. let me see...

@saulpw
Copy link
Owner

saulpw commented Nov 21, 2025

Oh, that would be great if you can simplify the sqlite with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants