Skip to content

Complete backend-python to be a full mirror of backend-node - #7

Merged
fiorionrails merged 1 commit into
mainfrom
copilot/complete-backend-python
Apr 5, 2026
Merged

Complete backend-python to be a full mirror of backend-node#7
fiorionrails merged 1 commit into
mainfrom
copilot/complete-backend-python

Conversation

Copilot AI commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

backend-python had data-loss bugs, missing endpoints, and no input validation — diverging significantly from the Node.js reference implementation.

Critical bugs fixed

  • process_debit never persisted — missing conn.commit() silently discarded every debit
  • recalculate_pending_boxes never persisted — same missing commit
  • NameError crash on POST /distributiondatetime used but not imported
  • App refused to start without .envadmin_token/secret_key had no defaults

Schema auto-initialization

get_db_connection() now creates all tables/views on first call, matching Node.js getDb() behavior. manage.py still works but is no longer required.

Missing features

utils.pyparse_positive_int / parse_non_negative_int: safe parsers that reject booleans, floats, negatives, and non-numeric strings (mirrors utils.js)

comanda_service.py

  • max_comandas enforced (MaxComandasReachedError)
  • DuplicateCodeError on concurrent code collision via sqlite3.IntegrityError
  • Zero initial_balance no longer inserts a phantom credit event

box_service.pyclaim_box replaced SELECT→UPDATE pattern with a single atomic UPDATE … WHERE responsible_name IS NULL AND status = 'pending' to eliminate the race condition

ws_admin.py + ws_store.py

  • Rate limiting: 300 msg/min per connection (STRESS_NO_RATELIMIT=true to bypass)
  • Max connection limits via MAX_ADMIN_CONNECTIONS / MAX_STORE_CONNECTIONS env vars
  • Auth checked before adding socket to active pool
  • All inputs validated with parse_positive_int / parse_non_negative_int
  • ws_store: tracks store_id per connection; disconnect_store_by_id() closes sockets on token revocation
  • ws_admin: maybeFlagRecalc called after cart-item changes

rest.py

  • PUT /distribution/:id/activate now archives the previously active distribution
  • DELETE /distribution/:id added (was missing entirely)
  • POST /stores/:id/revoke_token disconnects active WebSocket sessions
  • POST /stores and POST /categories return 201
  • Name/price validation on store and category creation

@vercel

vercel Bot commented Apr 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
feira-da-troca Ready Ready Preview, Comment Apr 5, 2026 3:46am
feira-da-troca-ba9e Ready Ready Preview, Comment Apr 5, 2026 3:46am

@fiorionrails
fiorionrails marked this pull request as ready for review April 5, 2026 03:47
@fiorionrails
fiorionrails merged commit 3fe2f4d into main Apr 5, 2026
4 checks passed
@fiorionrails
fiorionrails deleted the copilot/complete-backend-python branch April 5, 2026 03:47
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

Successfully merging this pull request may close these issues.

2 participants