sqlmodel
sqlmodel copied to clipboard
Field cannot autocompletion when its a SQLModel
Privileged issue
- [ ] I'm @tiangolo or he asked me directly to create an issue here.
Issue Content
Sorry for create this issue without permission, because this question has been in the discussion area for a week but no one has paid attention to it.
First Check
- [X] I added a very descriptive title here.
- [X] I used the GitHub search to find a similar question and didn't find it.
- [X] I searched the SQLModel documentation, with the integrated search.
- [X] I already searched in Google "How to X in SQLModel" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to SQLModel but to Pydantic.
- [X] I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
from sqlmodel import SQLModel
from typing import Optional
class ModelNode(SQLModel):
id: int
name: str
class Node:
id: int
name: str
class Cluster(SQLModel):
model_node: Optional[ModelNode] = None
node: Optional[Node] = None
Description
Cluster.node. can autocompletion, but Cluster.model_node. cannot
Operating System
macOS
Operating System Details
IDE: vscode
SQLModel Version
0.0.16
Python Version
3.10.5
Additional Context
@zhaowcheng If you create a new object from this class, the autocompletion works:
Also if you try to access to the property directly:
So not sure what is happening in your end (maybe any VS code configuration is missing?)
@asacristani , thank you for your answer.
I downgraded pydantic from v2
to v1
and it worked.
Is this a bug in sqlmodel?
Autocomplete worked for me with latest version of sqlmodel and pydantic2.5.3 (Python3.11/Pycharm)
@waketzheng
yes, pycharm
can autocomplete when pydantic is v2
, but vscode
cannot.
@waketzheng yes,
pycharm
can autocomplete when pydantic isv2
, butvscode
cannot.
same issue in vscode on windows
I usually develop on WSL1 for windows. And the autocompletion functionality works fine in my vscode.
And my packages infos are below:
pydantic 2.7.1 Data validation using Python type hints
sqlmodel 0.0.18 SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.
I usually develop on WSL1 for windows. And the autocompletion functionality works fine in my vscode.
And my packages infos are below:
pydantic 2.7.1 Data validation using Python type hints sqlmodel 0.0.18 SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.
After updating to the versions that you mention it got fixed!
On sqlmodel 0.0.16 + SQLALchemy 2.0.28 + pydantic 2.6.4 it was not working!