Skip to content

Commit

Permalink
Parts Browser: Run queued changes in reverse (#2387)
Browse files Browse the repository at this point in the history
This prevents an edge case I encountered where the following occurs:
- The user creates a new part, and forgets to add certain info (in my case, I forgot to check the "RP-1" box), and presses "Queue Changes"
- The user edits that part
- The user presses "Commit to JSON"
- Operation fails, console shows exception:
```
Traceback (most recent call last):
  File "flask\app.py", line 2190, in wsgi_app
  File "flask\app.py", line 1486, in full_dispatch_request
  File "flask\app.py", line 1484, in full_dispatch_request
  File "flask\app.py", line 1469, in dispatch_request
  File "app.py", line 168, in commit_changes
    part_data.add_new_part(part)
  File "part_data.py", line 25, in add_new_part
    print(f'Adding new part with name: {new_part["name"]}')
                                        ~~~~~~~~^^^^^^^^
KeyError: 'name'
```

This is because the "edit" queued change is executed before the part is even created, causing issues. Running queued changes in reverse should prevent any issues with this in most cases, assuming the browser/frontend is sane and does not randomly order queued changes.
  • Loading branch information
ThePuzzlemaker authored Jul 13, 2024
1 parent 98b5d74 commit 7ba2ff0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/Tech Tree/Parts Browser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def reload_data():
@app.route('/api/commit_changes', methods=['POST'])
def commit_changes():
queued_changes = request.get_json()
for row_id in queued_changes['queued_changes']:
for row_id in reversed(queued_changes['queued_changes']):
new_part = False
part = None
# if the part name changed, we need to use the old name to find it, else use the supplied name field
Expand Down Expand Up @@ -219,4 +219,4 @@ def ecm_tree():


if __name__ == "__main__":
create_app()
create_app()

0 comments on commit 7ba2ff0

Please sign in to comment.