|
| 1 | +"""drop results.python_exception (PickleType) |
| 2 | +
|
| 3 | +Revision ID: 7c2e1f4b8a90 |
| 4 | +Revises: 9b4e2c1a7d50 |
| 5 | +Create Date: 2026-05-19 00:00:00.000000 |
| 6 | +
|
| 7 | +Removes the ``python_exception`` column on ``results``, which used |
| 8 | +SQLAlchemy ``PickleType``. Loading that column unpickled arbitrary bytes |
| 9 | +from the database on every result read, which is an insecure- |
| 10 | +deserialization sink (RCE primitive given any DB write capability). |
| 11 | +
|
| 12 | +The column was not used by application logic, so the existing pickled blobs are discarded. |
| 13 | +Full exception details are logged to Application Insights via ``logger.exception`` instead |
| 14 | +of being persisted in the database. |
| 15 | +""" |
| 16 | + |
| 17 | +from typing import Sequence, Union |
| 18 | + |
| 19 | +import sqlalchemy as sa |
| 20 | +from alembic import op |
| 21 | + |
| 22 | + |
| 23 | +revision: str = "7c2e1f4b8a90" |
| 24 | +down_revision: Union[str, Sequence[str], None] = "9b4e2c1a7d50" |
| 25 | +branch_labels: Union[str, Sequence[str], None] = None |
| 26 | +depends_on: Union[str, Sequence[str], None] = None |
| 27 | + |
| 28 | + |
| 29 | +def upgrade() -> None: |
| 30 | + op.drop_column("results", "python_exception") |
| 31 | + |
| 32 | + |
| 33 | +def downgrade() -> None: |
| 34 | + # Restore the column shape for compatibility, but not the data: |
| 35 | + # re-creating PickleType data would require reintroducing the |
| 36 | + # deserialization sink that this migration exists to remove. |
| 37 | + op.add_column( |
| 38 | + "results", |
| 39 | + sa.Column("python_exception", sa.PickleType(), nullable=True), |
| 40 | + ) |
0 commit comments