sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Field cannot autocompletion when its a SQLModel

Open zhaowcheng opened this issue 10 months ago • 7 comments

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

image

image

zhaowcheng avatar Apr 09 '24 04:04 zhaowcheng

@zhaowcheng If you create a new object from this class, the autocompletion works: image Also if you try to access to the property directly: image

So not sure what is happening in your end (maybe any VS code configuration is missing?)

asacristani avatar Apr 14 '24 22:04 asacristani

@asacristani , thank you for your answer.

I downgraded pydantic from v2 to v1 and it worked.

Is this a bug in sqlmodel?

zhaowcheng avatar Apr 15 '24 03:04 zhaowcheng

Autocomplete worked for me with latest version of sqlmodel and pydantic2.5.3 (Python3.11/Pycharm) image

image

waketzheng avatar Apr 15 '24 17:04 waketzheng

@waketzheng yes, pycharm can autocomplete when pydantic is v2, but vscode cannot.

zhaowcheng avatar Apr 16 '24 09:04 zhaowcheng

@waketzheng yes, pycharm can autocomplete when pydantic is v2, but vscode cannot.

same issue in vscode on windows

dipsx avatar Apr 23 '24 13:04 dipsx

I usually develop on WSL1 for windows. And the autocompletion functionality works fine in my vscode. image

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.

Abeautifulsnow avatar May 11 '24 08:05 Abeautifulsnow

I usually develop on WSL1 for windows. And the autocompletion functionality works fine in my vscode. image

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!

JoseMMerida avatar Jun 03 '24 08:06 JoseMMerida