Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: String length ignored when generating values for SQLAlchemy models #592

Open
1 of 4 tasks
kadams54 opened this issue Oct 22, 2024 · 0 comments · May be fixed by #594
Open
1 of 4 tasks

Bug: String length ignored when generating values for SQLAlchemy models #592

kadams54 opened this issue Oct 22, 2024 · 0 comments · May be fixed by #594
Labels
bug Something isn't working

Comments

@kadams54
Copy link

kadams54 commented Oct 22, 2024

Description

Polyfactory's SQLAlchemyFactory doesn't seem to respect the string length specified when populating a SQLAlchemy model. For example, a field defined as mapped_column(String(1)) is consistently assigned a 20 character string. Ditto for a field defined as mapped_column(String(100))–also consistently a 20 character string. (20 character strings seem to be the default length for the underlying faker.pystr() provider.)

URL to code causing the issue

No response

MCVE

from sqlalchemy import create_engine, Engine, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session
from polyfactory.factories.sqlalchemy_factory import SQLAlchemyFactory

class Base(DeclarativeBase): ...

class Cat(Base):
    __tablename__ = "cats"
    id: Mapped[str] = mapped_column(String(10), primary_key=True)
    name: Mapped[str] = mapped_column(String(10))

class CatFactory(SQLAlchemyFactory[Cat]): ...

cat = CatFactory.build()
len(cat.id)   # 20
len(cat.name) # 20

Steps to reproduce

The MCVE code should be adequate to reproduce the issue with the latest (2.17.0) version of polyfactory.

Release Version

2.17.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@kadams54 kadams54 added the bug Something isn't working label Oct 22, 2024
@adhtruong adhtruong linked a pull request Oct 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant