Skip to content

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

Closed

Description

@mudassirkhan19

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

Activity

  1. 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[/+] on Oct 28, 2021
  2. mudassirkhan19 commented on Oct 28, 2021

    @mudassirkhan19
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions