Title: parse_obj return type is SQLModel · Issue #317 · fastapi/sqlmodel · GitHub
Open Graph Title: parse_obj return type is SQLModel · Issue #317 · fastapi/sqlmodel
X Title: parse_obj return type is SQLModel · Issue #317 · fastapi/sqlmodel
Description: 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...
Open Graph Description: 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...
X Description: 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 searc...
Opengraph URL: https://github.com/fastapi/sqlmodel/issues/317
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"parse_obj return type is SQLModel","articleBody":"### First Check\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\nfrom sqlmodel import SQLModel\r\n\r\nclass test(SQLModel):\r\n attr: int\r\n desc: str\r\n\r\nclass real(test, table=True):\r\n val: float\r\n\r\ntest_inst: test = test(attr=1, desc='test_inst')\r\nreal_inst: real = real.parse_obj(test_inst.dict())\r\n\"\"\"\r\n(method) parse_obj: (obj: Any, update: Dict[str, Any] | None = None) -> SQLModel\r\nExpression of type \"SQLModel\" cannot be assigned to declared type \"real\"\r\n \"SQLModel\" is incompatible with \"real\"PylancereportGeneralTypeIssues\r\n\"\"\"\r\n```\r\n\r\n\r\n### Description\r\n\r\nreal.parse_obj return type should be real.\r\n\r\n### Wanted Solution\r\n\r\n```python\r\n# sqlmodel/main.py\r\n\r\nfrom typing import TypeVar\r\n_T = TypeVar(\"_T\", bound=\"SQLModel\")\r\n\r\n(...)\r\n\r\n# line no.569\r\n @classmethod\r\n def parse_obj(\r\n cls: Type[_T], obj: Any, update: Optional[Dict[str, Any]] = None\r\n ) -> _T:\r\n obj = cls._enforce_dict_if_root(obj)\r\n # SQLModel, support update dict\r\n if update is not None:\r\n obj = {**obj, **update}\r\n # End SQLModel support dict\r\n return super().parse_obj(obj)\r\n```\r\n\r\n### Wanted Code\r\n\r\n...\r\n\r\n\r\n### Alternatives\r\n\r\nIt's being used temporarily like this.\r\n\r\n```python\r\nfrom typing import Any, TypeVar, cast\r\n\r\nfrom sqlmodel import SQLModel\r\n\r\n_T = TypeVar(\"_T\", bound=SQLModel)\r\n\r\n\r\nclass fix_parse_obj_model(SQLModel):\r\n @classmethod\r\n def parse_obj(cls: type[_T], obj: Any, update: dict[str, Any] | None = None) -> _T:\r\n return cast(_T, super().parse_obj(obj, update))\r\n```\r\n\r\n### Operating System\r\n\r\nLinux\r\n\r\n### Operating System Details\r\n\r\nOS: Arch Linux x86_64 \r\nHost: 82FX Yoga Slim 7 Pro 14ITL5 \r\nKernel: 5.17.4-arch1-1 \r\nUptime: 3 hours, 32 mins \r\nPackages: 969 (pacman), 23 (flatpak) \r\nShell: zsh 5.8.1 \r\nResolution: 2240x1400, 2560x1080 \r\nDE: GNOME 42.0 \r\nWM: Mutter \r\nWM Theme: Adwaita \r\nTheme: Arc [GTK2/3] \r\nIcons: Papirus [GTK2/3] \r\nTerminal: vscode \r\nCPU: 11th Gen Intel i5-1135G7 (8) @ 4.200GHz \r\nGPU: Intel TigerLake-LP GT2 [Iris Xe Graphics] \r\nGPU: NVIDIA GeForce MX450 \r\nMemory: 5423MiB / 15785MiB\r\n\r\n### SQLModel Version\r\n\r\n0.0.6\r\n\r\n### Python Version\r\n\r\nPython 3.10.4\r\n\r\n### Additional Context\r\n\r\nI'd like to do a \"pull requests\"\r\nshame I'm not used to git yet...","author":{"url":"https://github.com/phi-friday","@type":"Person","name":"phi-friday"},"datePublished":"2022-04-28T13:14:49Z","url":"https://github.com/fastapi/sqlmodel/issues/317"}
| 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:2aca1597-5057-200e-a92a-8e58143c236c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B1EC:2A1761:1713D2:1FCBC9:6AFE0544 |
| html-safe-nonce | a4379a65f0955ec3128f9940d5630ac439582cf2788ccfe674177c5b342adf62 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUVDOjJBMTc2MToxNzEzRDI6MUZDQkM5OjZBRkUwNTQ0IiwidmlzaXRvcl9pZCI6IjY1NjQxODUzNzI4MjQwNDQ4NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 74a01019296353a5a9b72b4e1c8c04014278c7a66d9d5da06fc69ee623850553 |
| hovercard-subject-tag | issue:1218714249 |
| 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/317/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2dfd2f074964a02da7a488a95e8e630438c39cd211bfa8ce86d9061531f4c1af/fastapi/sqlmodel/issues/317 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2dfd2f074964a02da7a488a95e8e630438c39cd211bfa8ce86d9061531f4c1af/fastapi/sqlmodel/issues/317 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | phi-friday |
| hostname | github.com |
| expected-hostname | github.com |
| None | 86d46ece7c3d9b0562692f81a135cb55ad6a1c82c93ab1ac874d2f1b46b28958 |
| 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 | 5c18e6799976b7bc2f21178024289bb98edbcc85 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width