fix: align CustomCommandCreator.discord_id model with BIGINT column (#78) #88
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#88
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/78-fix-discord-id-type-mismatch-between-model-charfie"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #78
Summary
CustomCommandCreator.discord_idfromCharField(max_length=20, unique=True)toBigIntegerField(unique=True)inapp/db_engine.pyto match theBIGINT UNIQUE NOT NULLcolumn created bymigrations/add_custom_commands_tables.sqlstr(discord_id)workaround inget_creator_by_discord_id()(custom_commands.py:178) that was compensating for the type mismatch — the ORM can now compare integers directlyFiles Changed
app/db_engine.py— model field type correctedapp/routers_v3/custom_commands.py—str()cast removed from ORM queryTest Results
No test suite in this repo. Changes verified by reading the modified files and confirming the diff is minimal and correct.
Other Observations
CustomCommandCreatorModel(Pydantic,custom_commands.py:26) already declaresdiscord_id: int, so no API contract change.help_commands.py:29declarescreated_by_discord_id: strwith a comment "Text to safely store Discord snowflake IDs" — that router uses raw SQL, not the Peewee ORM, and references a separatehelp_commandstable. Out of scope for this fix.Review: APPROVED
Minimal, correct fix. Two-line change that removes a type mismatch between the Peewee ORM and the actual PostgreSQL schema.
Verification
Migration confirms the schema:
migrations/add_custom_commands_tables.sqlline 8 —discord_id BIGINT UNIQUE NOT NULL. The oldCharField(max_length=20)was wrong from the start.BigIntegerFieldavailability:db_engine.pyusesfrom peewee import *—BigIntegerFieldis a standard Peewee field type, available in scope.str()cast removal: WithCharField, Peewee passed strings to PostgreSQL which implicitly coerced them. WithBigIntegerField, Peewee now generates a proper integer parameter — correct and type-safe.Full discord_id surface area checked:
CustomCommandCreatorModel.discord_id: int(Pydantic, line 26) — alreadyint, no API contract changecreate_creator_endpoint(line 702) — callsget_creator_by_discord_id(creator.discord_id)wherecreator.discord_idisintfrom Pydantic model — correctcreate_creator(creator_data)(line 711) —creator.model_dump()includesdiscord_idasint— correctget_creatorsendpoint (line 633-635) — uses raw SQLdiscord_id = %swith int param — was already type-safe, unaffectedcreator_discord_idusages — raw SQL column reads, unaffected by ORM field typeDiscord snowflake range: PostgreSQL
BIGINTholds up to ~9.2×10^18. Current Discord snowflakes are ~1.3×10^18 — well within range, no overflow risk.Pre-existing (not blocking)
custom_commands.py:697—Bad Token: {token}still exposes bearer token in logs — tracked by the PR #85 pattern, butcreate_creator_endpointwas not in scope for that fixdb_engine.py:21— hardcoded fallback password still present — tracked by PR #84 (approved but not yet reflected in this branch)Checkout
From your project repository, check out a new branch and test the changes.