Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it normal unable to use autocomplete for SQLModel class field? #483

Closed
8 tasks done
ggree1 opened this issue Nov 3, 2022 · 14 comments
Closed
8 tasks done

Is it normal unable to use autocomplete for SQLModel class field? #483

ggree1 opened this issue Nov 3, 2022 · 14 comments
Labels
question Further information is requested

Comments

@ggree1
Copy link

ggree1 commented Nov 3, 2022

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

class Hero1(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    secret_name: str
    age: Optional[int] = None


class Hero2():
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    secret_name: str
    age: Optional[int] = None

Description

I'm using Pycharm.
When I write code like,
select(Hero1).where(Hero1.age > 35)

I expect IDE to show field 'age' when I type 'Hero1.' but IDE autocomplete displays no fields of Hero1.
but with Hero2 (without SQLModel inherits), it surely works fine.

Is this normal or only my IDE problem?

Operating System

Windows

Operating System Details

windows 10
Pycharm 2022

SQLModel Version

0.0.8

Python Version

3.10.6

Additional Context

image

image

@ggree1 ggree1 added the question Further information is requested label Nov 3, 2022
@linpan
Copy link

linpan commented Nov 3, 2022

@ggree1 need pydantic plugins.
image

@ggree1
Copy link
Author

ggree1 commented Nov 3, 2022

already installed and no problem with pydantic model. Anyway it looks my IDE problem.. thanks.

@tiangolo
Copy link
Member

tiangolo commented Nov 3, 2022

It's probably that PyCharm still doesn't support dataclass_transform, that's a new standard in Python and it was adopted by Pydantic and SQLModel even before it was an official standard.

You can probably ask them to add support for it. 🤓

@linpan
Copy link

linpan commented Nov 4, 2022

@tiangolo I will report this to JetBrains

@github-actions github-actions bot removed the answered label Nov 4, 2022
@ggree1
Copy link
Author

ggree1 commented Nov 4, 2022

Thanks @tiangolo, @linpan.
I'm closing this issue.

@ggree1 ggree1 closed this as completed Nov 4, 2022
@tiangolo
Copy link
Member

tiangolo commented Nov 6, 2022

Thanks @linpan ! And thanks for coming back to close it @ggree1

@linpan
Copy link

linpan commented Nov 7, 2022

@ggree1 @tiangolo has already support PyCharm 2022.2.3. Fastapi and Pydantic will more power and productivity
20221107-103733

@ggree1
Copy link
Author

ggree1 commented Nov 7, 2022

@linpan Thanks for the clarification. Actually I'm a Java developer so I was using latest IntelliJ with python plugin which supports almost same as Pycharm. I guess the python plugin has not yet updated this funcionality.

@tiangolo
Copy link
Member

tiangolo commented Nov 7, 2022

Just a note, autocompletion for attributes would work even without support for dataclass_transform. What dataclass_transform would help with is autocompletion for parameters when creating a new instance of the class.

@hydenp
Copy link

hydenp commented May 13, 2024

Was there a solution to this issue? I am using Pycharm 2024.1.1 and still running into this issue :( @linpan it seems to be working for you..?

My user model is as follows

class UserModel(UserBase, table=True):
    __tablename__ = "_user"
    id: int | None = Field(default=None, primary_key=True)

With the others looking much the same

Here is what Pycharm looks like

Screenshot 2024-05-12 at 8 58 05 PM

EDIT: to possibly answer my own question, it looks like this may be related to this PyCharm issue

https://youtrack.jetbrains.com/issue/PY-54560/Support-PEP-681-typing.dataclasstransform

is that correct?

@linpan
Copy link

linpan commented May 14, 2024

still have. SQLAlchemy have not autocompletion ,when instance.

@HeiziND
Copy link

HeiziND commented Jun 12, 2024

@hydenp

I am experiencing exactly the same issue as you. I believe however that it is a problem with the pydantic plugin for pycharm.

To illustrate the issue, please see the below minimal example. I'm too swamped to do it now, but you're welcome to raise it as issue there in their repo

code
image

@hydenp
Copy link

hydenp commented Jun 12, 2024

@HeiziND i opened an issue on JetBrains here

https://youtrack.jetbrains.com/issue/PY-72886/No-autocomplete-with-SQLModel-when-interpreter-specified

If it is with the plugin, I will possibly look into raising it there.

The weird thing is that autocomplete works perfectly when the interpreter is removed from the project. See the above issue for an example of that.

@gbaian10
Copy link

gbaian10 commented Aug 9, 2024

I have the same issue.
I'm not sure if it's my personal problem or a problem with PyCharm itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants