Title: [Question] Why are pydantic validation results ignored for models with `table=True`? Where are the benefits? · Issue #406 · fastapi/sqlmodel · GitHub
Open Graph Title: [Question] Why are pydantic validation results ignored for models with `table=True`? Where are the benefits? · Issue #406 · fastapi/sqlmodel
X Title: [Question] Why are pydantic validation results ignored for models with `table=True`? Where are the benefits? · Issue #406 · fastapi/sqlmodel
Description: First Check EDIT: See #406 (comment) 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 search...
Open Graph Description: First Check EDIT: See #406 (comment) 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...
X Description: First Check EDIT: See #406 (comment) 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, ...
Opengraph URL: https://github.com/fastapi/sqlmodel/issues/406
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Question] Why are pydantic validation results ignored for models with `table=True`? Where are the benefits?","articleBody":"### First Check\r\n\r\n**EDIT: See https://github.com/tiangolo/sqlmodel/issues/406#issuecomment-1225706569**\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\nimport enum\r\nfrom pydantic import BaseModel, ValidationError\r\nfrom sqlmodel import Field, SQLModel\r\n\r\n\r\nclass EnumValues(str, enum.Enum):\r\n\r\n FOO = \"foo\"\r\n BAR = \"bar\"\r\n\r\n\r\nclass TableModel(BaseModel):\r\n value: EnumValues\r\n\r\n\r\nprint(TableModel(value=\"bar\")) # value=\u003cEnumValues.BAR: 'bar'>\r\ntry:\r\n print(TableModel(value=\"baz\"))\r\nexcept ValidationError as e:\r\n print(e)\r\n # 1 validation error for TableModel\r\n # value\r\n # value is not a valid enumeration member; permitted: 'foo', 'bar' (type=type_error.enum; enum_values=[\u003cEnumValues.FOO: 'foo'>, \u003cEnumValues.BAR: 'bar'>])\r\n\r\n\r\nclass TableBase(SQLModel):\r\n value: EnumValues\r\n\r\n\r\nprint(TableBase(value=\"bar\")) # value=\u003cEnumValues.BAR: 'bar'>\r\ntry:\r\n print(TableBase(value=\"baz\"))\r\nexcept ValidationError as e:\r\n print(e)\r\n # 1 validation error for TableBase\r\n # value\r\n # value is not a valid enumeration member; permitted: 'foo', 'bar' (type=type_error.enum; enum_values=[\u003cEnumValues.FOO: 'foo'>, \u003cEnumValues.BAR: 'bar'>])\r\n\r\n\r\nclass Table(TableBase, table=True):\r\n id: int | None = Field(default=None, nullable=False, primary_key=True) # noqa: VNE003\r\n\r\n\r\nprint(Table(value=\"bar\")) # value=\u003cEnumValues.BAR: 'bar'> id=None\r\ntry:\r\n print(Table(value=\"baz\")) # id=None\r\nexcept ValidationError as e:\r\n print(e) # NEVER REACHED\r\n```\r\n\r\n\r\n### Description\r\n\r\n* make a instance of the TableModel which is a pure pydantic model with a valid string in the enum -> success (as it should be)\r\n* make a instance of the TableModel which is a pure pydantic model with an invalid string in the enum -> error (as it should be)\r\n* make a instance of the TableBase which is not `table=True` with a valid string in the enum -> success (as it should be)\r\n* make a instance of the TableBase which is not `table=True` with an invalid string in the enum -> error (as it should be)\r\n* make a instance of the Table which is `table=True` with a valid string in the enum -> success (as it should be)\r\n* make a instance of the Table which is `table=True` with an invalid string in the enum -> success (should be error, but creates an instance which is totally missing the non-optional and non-default `value` field)\r\n\r\n### Operating System\r\n\r\nLinux\r\n\r\n### Operating System Details\r\n\r\nUbuntu\r\n\r\n### SQLModel Version\r\n\r\n0.0.6\r\n\r\n### Python Version\r\n\r\n3.10.4\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/Cielquan","@type":"Person","name":"Cielquan"},"datePublished":"2022-08-24T10:54:46Z","url":"https://github.com/fastapi/sqlmodel/issues/406"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:29535f2f-a0cb-d77f-f12c-4c8deb5f2b5d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B34:2EDF53:DA185:12E25B:6AFDF75C |
| html-safe-nonce | fbb7e68e1b1de709dffb0900bdcde8abd68ea047a2aaa12da3eee456f0acdf4a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjM0OjJFREY1MzpEQTE4NToxMkUyNUI6NkFGREY3NUMiLCJ2aXNpdG9yX2lkIjoiMzg3NDg2Nzg0NDk2OTUyNzEzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ddc44aadc737dd7ef7ce35571d91367e57d5b7077a8e1999b720de260e0d4928 |
| hovercard-subject-tag | issue:1349250751 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/406/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68603eaead9a4f6d6fea34f71193adb820cdb2d6582ac1fe8f20719b4387693c/fastapi/sqlmodel/issues/406 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68603eaead9a4f6d6fea34f71193adb820cdb2d6582ac1fe8f20719b4387693c/fastapi/sqlmodel/issues/406 |
| og:image:alt | First Check EDIT: See #406 (comment) 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Cielquan |
| hostname | github.com |
| expected-hostname | github.com |
| None | ee3343385a977757dd145b28fabf4a119780f2615a5a36c5a89f66c9b3b5616d |
| turbo-cache-control | no-preview |
| go-import | github.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git |
| octolytics-dimension-user_id | 156354296 |
| octolytics-dimension-user_login | fastapi |
| octolytics-dimension-repository_id | 399495186 |
| octolytics-dimension-repository_nwo | fastapi/sqlmodel |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 399495186 |
| octolytics-dimension-repository_network_root_nwo | fastapi/sqlmodel |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 43ae91995f6e2d5ff7a491f3de438f1f723adeaa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width