Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: custom fields now require dictionary access
Custom fields must now be accessed via `item.custom["my_custom_field"]` i.e. normal dictionary access. I changed this from normal attribute access as overriding `__getattr__` and `__setattr__` (required for transparent attribute access) had some finicky conflicts with sqlalchemy. Also, it prevented type hinting the custom attribute dictionary as well as integration with data serializers such as pydantic. Overall, the more I used them, the more issues I found, and the more it felt like a hack. I believe the new explicit dictionary access for custom attributes will prove to be more bulletproof. It also explicitly delineates normal and custom attributes which can be useful in some cases.
- Loading branch information
Showing
24 changed files
with
328 additions
and
396 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Rename custom fields. | ||
Revision ID: ab5db9861d30 | ||
Revises: 880c5a2d80ed | ||
Create Date: 2022-12-11 15:24:10.227924 | ||
""" | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ab5db9861d30" | ||
down_revision = "880c5a2d80ed" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
with op.batch_alter_table("album", schema=None) as batch_op: | ||
batch_op.alter_column("_custom_fields", new_column_name="custom") | ||
|
||
with op.batch_alter_table("extra", schema=None) as batch_op: | ||
batch_op.alter_column("_custom_fields", new_column_name="custom") | ||
|
||
with op.batch_alter_table("track", schema=None) as batch_op: | ||
batch_op.alter_column("_custom_fields", new_column_name="custom") | ||
|
||
|
||
def downgrade(): | ||
with op.batch_alter_table("track", schema=None) as batch_op: | ||
batch_op.alter_column("custom", new_column_name="_custom_fields") | ||
|
||
with op.batch_alter_table("extra", schema=None) as batch_op: | ||
batch_op.alter_column("custom", new_column_name="_custom_fields") | ||
|
||
with op.batch_alter_table("album", schema=None) as batch_op: | ||
batch_op.alter_column("custom", new_column_name="_custom_fields") |
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
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
Oops, something went wrong.