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

Adding a value to a Field greater than the max_length results in null values #148

Closed
8 tasks done
mudassirkhan19 opened this issue Oct 28, 2021 · 1 comment
Closed
8 tasks done
Labels
question Further information is requested

Comments

@mudassirkhan19
Copy link

mudassirkhan19 commented Oct 28, 2021

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Optional
from sqlmodel import SQLModel, Field

class Company(SQLModel, table=True):
    __tablename__ = "Company"  # type: ignore
    id: Optional[int] = Field(primary_key=True)
    name: str = Field(max_length=100)

c = Company(name="a" * 101)
print(c.name)
print(type(c.name))
c = Company(name="a" * 100)
print(c.name)
print(len(c.name))

Description

I have created a SQLModel with a string column and max_length constraint. If I add a value greater than the max_length constraint, instead of raising a validation error, the value is being set as None which isn't the desired behaviour, I have tried persisting the row to the db and I get an empty value there too (check third value).
Screenshot 2021-10-28 at 9 34 27 PM

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

Python 3.8.10

Additional Context

No response

@mudassirkhan19 mudassirkhan19 added the question Further information is requested label Oct 28, 2021
@mudassirkhan19 mudassirkhan19 changed the title Adding a value to a field greater than the max_length results in null values Adding a value to a Field greater than the max_length results in null values Oct 28, 2021
@mudassirkhan19
Copy link
Author

I'll close this, just found a similar issue here.
#134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant