Skip to content

Cleanup: Have Form.save_records and Form.prompt_save use save_record_recursive like Query.prompt_save #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ssweber opened this issue Feb 15, 2023 · 10 comments

Comments

@ssweber
Copy link
Collaborator

ssweber commented Feb 15, 2023

Writing this down so I don't forget details. 😄

  • Form.save_records and Form.prompt_save loop through queries to save.
  • Query.prompt_save starts at self.table, and calls save_record_recursive, which saves bottom child first and works its way back up to current table.

Looping through queries to save is an issue if a user has a child change its parent, thus requerying itself and its dependents. Any date unsaved in its dependents will be lost. Since Query.prompt_save saves the lowest first, if there is a requery, it's children are already saved.

While that is an edge-case, I like the idea of keeping the behavior consistent between all three saving methods.

Form.save_records:

  • for each top-level parent, call save_record_recursive.
  • Move debug lines (success/failure/no action) into Query.save_record.
  • Have save_record_recursive & save_record pass on (success/failure/no action) so that Form.save_records has information for final popup message. Eg, keep passing a SAVE_NONE, until a SAVE_SUCCESS, but override with a SAVE_FAIL
  • Modify save_record_recursive to pass on display_message=True

Form.prompt_save:

  • for each top-level parent, call if self[q].records_changed(recursive=True)
  • then for each true, call save_record_recursive. May need to modify save_record_recursive for an check_prompt_save=True flag to keep current behavior

One more small cleanup:
Query.save_record - it's flag is update_elements=True, while the rest use update=True. Consider switching to match

@ssweber ssweber mentioned this issue Feb 15, 2023
22 tasks
@PySimpleSQL
Copy link
Owner

As long as we keep things pretty much backwards compatible, I don't have a real preference on how we loop through the queries. In regards to re-parenting, It may even make more sense to do that at the SQL backend, then requery the changes in from there - it could get rid of a lot of complexity on the SS side.

Form.save_Records sounds logical. Again, the only concert would be remaining as backward compatible as possible

Yeah, Query.save_record should match the rest.

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 16, 2023

Ok. When I get to this I’ll make sure to replicate any behavior!

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 22, 2023

I’ll try to do this one tomorrow or Thursday.

bumped into it again, this time with virtual records.

Parent - insert virtual row
Child - insert virtual row
Child - hit save.

Depending on the query order, the child can be overwritten if the parent saves first, and requires/select by pk

so best to save lowest children first, then up :)

@PySimpleSQL
Copy link
Owner

PySimpleSQL commented Feb 22, 2023 via email

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 22, 2023

Oh, like if the parent is actually assigned a different pk (eg if is autoincremented.)

are you thinking of looking at SQLITE_SEQUENCE first?

@PySimpleSQL
Copy link
Owner

PySimpleSQL commented Feb 22, 2023 via email

@PySimpleSQL
Copy link
Owner

PySimpleSQL commented Feb 22, 2023 via email

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 22, 2023

Also, if this makes things simpler for you

  • on insert we could check if parent current row is virtual, and disallow child inserts before saving parent.

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 22, 2023

I know they have to worry about performance, their implementation and all that, but I always think it’s funny when databases say “typically” in their documentation.

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 23, 2023

#86 completes this

@ssweber ssweber closed this as completed Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants