Skip to content

fix: adding string representation to StoredObject - #582

Merged
cofin merged 2 commits into
litestar-org:mainfrom
ambrozic:patch-1
Oct 18, 2025
Merged

cofin merged 2 commits into
litestar-org:mainfrom
ambrozic:patch-1

Conversation

@ambrozic

Copy link
Copy Markdown
Contributor

Ran into an issues running migration created for advanced_alchemy.types.FileObject column on a model. Below details should shed some more light.

Code

from advanced_alchemy.base import UUIDBase
from advanced_alchemy.types.file_object.backends.obstore import ObstoreBackend
from advanced_alchemy.types import storages, FileObject, StoredObject
from sqlalchemy.orm import Mapped, mapped_column

file_storage_backend = ObstoreBackend(
    key="local",
    fs="file://",
    prefix="/path/to/files",
)
storages.register_backend(file_storage_backend)


class Document(UUIDBase):
    __tablename__ = "documents"
    file: Mapped[FileObject] = mapped_column(StoredObject(backend="local"))

Migration file

...

def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('documents',
    sa.Column('file', advanced_alchemy.types.file_object.data_type.StoredObject(), nullable=False),
    sa.Column('id', advanced_alchemy.types.guid.GUID(length=16), nullable=False),
    sa.Column('sa_orm_sentinel', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_documents'))
    )
    # ### end Alembic commands ###

Error
Happens when applying migrations

...
  File "/path/to/migrations/versions/202510161151_8b0d40f55e2b.py", line 28, in upgrade
    sa.Column('file', advanced_alchemy.types.file_object.data_type.StoredObject(), nullable=False),
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
TypeError: StoredObject.__init__() missing 1 required positional argument: 'backend'

Proposed change recommended by @glendonyeo fixes this issue.

Side quest would be to add advanced_alchemy.types.file_object.file.FileObject type support to polyfactory.

polyfactory.exceptions.ParameterException: Unsupported type: <class 'advanced_alchemy.types.file_object.file.FileObject'> on field '' from class ImageFactory.

@codecov-commenter

codecov-commenter commented Oct 16, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.51%. Comparing base (d26a68b) to head (c75a5ba).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
advanced_alchemy/types/file_object/data_type.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #582      +/-   ##
==========================================
- Coverage   79.55%   79.51%   -0.04%     
==========================================
  Files          87       87              
  Lines        6304     6308       +4     
  Branches      796      797       +1     
==========================================
+ Hits         5015     5016       +1     
- Misses       1041     1044       +3     
  Partials      248      248              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Gregor Ambrozic <ambrozic@users.noreply.github.com>
@cofin

cofin commented Oct 18, 2025

Copy link
Copy Markdown
Member

I've added a suggestion so that it also handles multiple files properly. It otherwise looks good!

Signed-off-by: Cody Fincher <204685+cofin@users.noreply.github.com>
@cofin
cofin merged commit e8ca206 into litestar-org:main Oct 18, 2025
1 check passed
@github-actions

Copy link
Copy Markdown

Documentation preview will be available shortly at https://litestar-org.github.io/advanced-alchemy-docs-preview/582

@ambrozic
ambrozic deleted the patch-1 branch October 18, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants