-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate the cipher length and base64 length ahead of time. (Fixes #853
) (#854) * Calculate the cipher length and base64 length ahead of time. (Fixes #853) We also fix up an existing issue with a user's schedules.details field. * Allow details and location_url to be nullable for requests.
- Loading branch information
1 parent
2a47a17
commit 7625b54
Showing
5 changed files
with
489 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ntment/migrations/versions/2025_02_05_1839-645fd31f827d_clean_invalid_schedule_details.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""clean invalid schedule details | ||
Revision ID: 645fd31f827d | ||
Revises: 4a15d01919b8 | ||
Create Date: 2025-02-05 18:39:12.277713 | ||
""" | ||
import binascii | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Session | ||
import base64 | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '645fd31f827d' | ||
down_revision = '4a15d01919b8' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
session = Session(op.get_bind()) | ||
bad_fields_found = 0 | ||
rows = session.execute(sa.text('SELECT id, details FROM schedules WHERE details is not null;')).all() | ||
for row in rows: | ||
id, details = row | ||
try: | ||
base64.b64decode(details) | ||
except binascii.Error: | ||
bad_fields_found += 1 | ||
statement = sa.text('UPDATE schedules SET details = NULL WHERE id = :id') | ||
statement = statement.bindparams(id=id) | ||
op.execute(statement) | ||
|
||
print(f'Nulled {bad_fields_found} schedules.details fields.') | ||
|
||
|
||
def downgrade() -> None: | ||
pass |
Oops, something went wrong.