GrandMoff100 / HomeAssistantAPI

Python Wrapper for Homeassistant's REST API
https://homeassistantapi.readthedocs.io
GNU General Public License v3.0
65 stars 20 forks source link

[Library Bug] NameError: name 'Client' is not defined #188

Open thex1le opened 1 week ago

thex1le commented 1 week ago

Describe the bug attempting to import home assistant returns the following trace back..

`Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

from homeassistant_api import Client Traceback (most recent call last): File "", line 1, in File "/home/textile/HomeAssistantAPI/homeassistant_api/init.py", line 26, in from .client import Client File "/home/textile/HomeAssistantAPI/homeassistant_api/client.py", line 5, in from .rawasyncclient import RawAsyncClient File "/home/textile/HomeAssistantAPI/homeassistant_api/rawasyncclient.py", line 26, in from .models import Domain, Entity, Event, Group, History, LogbookEntry, State File "/home/textile/HomeAssistantAPI/homeassistant_api/models/init.py", line 3, in from .domains import Domain, Service, ServiceField File "/home/textile/HomeAssistantAPI/homeassistant_api/models/domains.py", line 15, in class Domain(BaseModel): File "/home/textile/.local/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 114, in new private_attributes = inspect_namespace( ^^^^^^^^^^^^^^^^^^ File "/home/textile/.local/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 448, in inspect_namespace ann_type = eval_type_backport( ^^^^^^^^^^^^^^^^^^^ File "/home/textile/.local/lib/python3.11/site-packages/pydantic/_internal/_typing_extra.py", line 279, in eval_type_backport return _eval_type_backport(value, globalns, localns, type_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/textile/.local/lib/python3.11/site-packages/pydantic/_internal/_typing_extra.py", line 303, in _eval_type_backport return _eval_type(value, globalns, localns, type_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/textile/.local/lib/python3.11/site-packages/pydantic/_internal/_typing_extra.py", line 332, in _eval_type return typing._eval_type( # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/typing.py", line 359, in _eval_type return t._evaluate(globalns, localns, recursive_guard) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/typing.py", line 857, in _evaluate eval(self.__forward_code__, globalns, localns), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1, in NameError: name 'Client' is not defined`

To Reproduce Steps to reproduce the behavior:

  1. Download latest code from github or install from pip3 on raspberry pi OS bookworm. In my case I am using a pi5 but i tested and it also happens on bookworm on a pi4. Both codebases have the issue

  2. Attempt to import home assistant api client in python3.11.2 from homeassistant_api import Client

  3. Receive Traceback

Expected behavior A clean import of the object to use

Desktop (please complete the following information):

GrandMoff100 commented 1 week ago

Hmm, pydantic shouldn't need to know where Client is, because Client isn't a model. I think the fix is to stop pydantic from trying to evaluate the annotations of private attributes.

However to be frankly honest with you, I'm taking a lot of classes this semester, and don't have the bandwidth to fix this immediately.

I might be able to get to it by next Saturday, or sometime before then.

thex1le commented 1 week ago

No worries, this is nothing critical and if I get some spare cycles I'll see if I can't find a work around. It used to work great and I am in the middle of a major refactor on my project so I was surprised when the important started failing.

On Fri, Sep 6, 2024, 14:43 Nathan Larsen @.***> wrote:

Hmm, pydantic shouldn't need to know where Client is, because Client isn't a model. I think the fix is to stop pydantic from trying to evaluate the annotations of private attributes.

However to be frankly honest with you, I'm taking a lot of classes this semester, and don't have the bandwidth to fix this immediately.

I might be able to get to it by next Saturday, or sometime before then.

— Reply to this email directly, view it on GitHub https://github.com/GrandMoff100/HomeAssistantAPI/issues/188#issuecomment-2334625656, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABA3TULCMNIBE34CS3CL7RDZVHZW3AVCNFSM6AAAAABNY7IX5CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZUGYZDKNRVGY . You are receiving this because you authored the thread.Message ID: @.***>

ducksauz commented 1 week ago

I'm going to +1 this issue, as I'm having the same problem. Also not critical for me, so I think I'll try an older version in the mean time. ETA: yeah, older version doesn't work due to issue:151

Guess I'll back burner this project for now then.

raoulwegat commented 1 week ago

+1 on RPIOS bullseye with python 3.9.2. No problem on macOS 14.6.1 with python 3.9.18.

neojjang commented 1 week ago

I have a same error -.-;; OS: mac M1 Pro (Sonoma 14.6.1) python : 3.12.5 HomeAssistant-API: 4.2.2.post1

ravngr commented 1 week ago

Just some clues. Looks like pydantic introduced some chance in the v2.9.x series that has upset this library. The dependencies in this project allows any version >=2.0 so it's obviously tripped up by an upstream change. I haven't dug through the change logs to figure out what that is.

Falling back to the previous minor version using pip install pydantic==2.8.2 worked for me. This version should probably be pinned or the change dealt with.

ducksauz commented 1 week ago

Can confirm.
Pinning pydantic==2.8.2 works for me as well.

mac 14.6.1 on arm64 Python 3.12.5 HomeAssistant-API: 4.2.2.post1