core icon indicating copy to clipboard operation
core copied to clipboard

Qnap Integration failing to setup

Open Yardco opened this issue 6 months ago • 29 comments

The problem

After upgrading to core-2025.5.0b0, the Qnap integration is failing to set up, showing the following error in the integration page: Failed setup, will retry: 'NoneType' object does not support the context manager protocol

What version of Home Assistant Core has the issue?

core-2025.4.4

What was the last working version of Home Assistant Core?

core-2025.5.0b0

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Qnap

Link to integration documentation on our website

https://rc.home-assistant.io/integrations/qnap

Diagnostics information

No response

Example YAML snippet


Anything in the logs that might be useful for us?

Unexpected error fetching qnap data

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 380, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/qnap/coordinator.py", line 86, in _async_update_data
    return await self.hass.async_add_executor_job(self._sync_update)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/qnap/coordinator.py", line 72, in _sync_update
    suppress_insecure_request_warning()
    if not self._verify_ssl
    else nullcontext()
  File "/usr/local/lib/python3.13/contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "/usr/src/homeassistant/homeassistant/components/qnap/coordinator.py", line 40, in suppress_insecure_request_warning
    with urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning):
         ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object does not support the context manager protocol

Additional information

No response

Yardco avatar May 01 '25 07:05 Yardco

Hey there @disforw, mind taking a look at this issue as it has been labeled with an integration (qnap) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of qnap can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign qnap Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


qnap documentation qnap source (message by IssueLinks)

home-assistant[bot] avatar May 01 '25 07:05 home-assistant[bot]

Same problem on released version 2025.5.0. Deleting integration and re-registering did not solve the problem "Failed setup, will retry: 'NoneType' object does not support the context manager protocol"

dpan avatar May 07 '25 18:05 dpan

bum up, same as @dpan

rommess avatar May 07 '25 22:05 rommess

same things happening for me

SpankGirl avatar May 08 '25 00:05 SpankGirl

I’m seeing the same thing after upgrading to 2025.05

aLTeReGo-SWI avatar May 08 '25 03:05 aLTeReGo-SWI

Same here

smoki3 avatar May 08 '25 04:05 smoki3

I’m seeing the same thing after upgrading to 2025.05 this evening.

jlipsit avatar May 08 '25 04:05 jlipsit

Same issue here after upgrading to 2025.5

mattdevo1 avatar May 08 '25 04:05 mattdevo1

Same here. Removing an adding back is not working.

rest77 avatar May 08 '25 04:05 rest77

Same issue here after upgrading to 2025.5

Mverhovcev avatar May 08 '25 07:05 Mverhovcev

Same here and would really appreciate a fix @disforw, because its the only misfunction after the upgrade to 2025.5.0 💪

NetRat88 avatar May 08 '25 07:05 NetRat88

Same issue here after upgrading to 2025.5

kastro123 avatar May 08 '25 07:05 kastro123

For me after the upgrade to 2025.5 the Integration still works for my older QNAP-device running firmware version 4.3.6.2805, but fails for the newer one running QTS 5.2.3.3006

cyriax avatar May 08 '25 08:05 cyriax

Same for me, I own an old QNAP with v4 firmware and a newer one with v5 firmware, both of them have issues after upgrading to 2025.5

sna696 avatar May 08 '25 08:05 sna696

I guess this issue was introduced in PR https://github.com/home-assistant/core/pull/141752 by @frenck. I think urllib3.disable_warnings() is not a context manager, that's where the TypeError comes from.

jrieger avatar May 08 '25 12:05 jrieger

Same since the last update 😥

BrianFr88 avatar May 08 '25 14:05 BrianFr88

same issue the last update 2025.5. My last avaliable QTS version is 4.2.6 build 20240618, so I could not upgrade QNAP. I have tried with/without force ssl connection, with/without ssl verification during reconnecting. It is not possible to re-add the removed QNAP device on the integration.

2025-05-08 17:01:00.242 ERROR (MainThread) [aiohttp.server] Error handling request from <my external IP>
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py", line 510, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/aiohttp/web_app.py", line 569, in _handle
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 86, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 41, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 233, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 121, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 336, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 383, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        flow, cur_step["step_id"], user_input
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 487, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/qnap/config_flow.py", line 77, in async_step_user
    unique_id = stats["system"]["serial_number"]
                ~~~~~^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

zollak avatar May 08 '25 15:05 zollak

same here

codo70 avatar May 08 '25 21:05 codo70

Me to, on HAOS, but I rolled back to 2025.4.

Tukamok avatar May 08 '25 21:05 Tukamok

La même chose, le retour à la 2025.4 résolu le problème pour l'instant

GitHu-bro avatar May 09 '25 06:05 GitHu-bro

I managed to mitigate the issue on my setup and get it running again (for now) by changing the following lines in coordinator.py.

/usr/src/homeassistant/homeassistant/components/qnap/coordinator.py

@contextmanager def suppress_insecure_request_warning(): with urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning): yield

with

@contextmanager def suppress_insecure_request_warning(): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) try: yield finally: pass # can't re-enable warnings, but this avoids crashing

I haven't tested if this works with SSL certificates. Remember to always verify your code and make backups before running it!

tascrafts avatar May 10 '25 00:05 tascrafts

I just updated to 2025.5.1 and the problem persists.

patxo avatar May 10 '25 08:05 patxo

啥时候能更新修复啊,太影响使用了

YXWHome avatar May 11 '25 01:05 YXWHome

能把刷新时间开出来自己设置就好了,这样想要实时数据的可以将刷新时间设置小点,不需要的就默认时间

YXWHome avatar May 11 '25 07:05 YXWHome

I managed to mitigate the issue on my setup and get it running again (for now) by changing the following lines in coordinator.py.

/usr/src/homeassistant/homeassistant/components/qnap/coordinator.py

@contextmanager def suppress_insecure_request_warning(): with urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning): yield

with

@contextmanager def suppress_insecure_request_warning(): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) try: yield finally: pass # can't re-enable warnings, but this avoids crashing

I haven't tested if this works with SSL certificates. Remember to always verify your code and make backups before running it!

Thanks for this! I was able to mitigate the issue with the following details:

  1. It works both on HTTP and HTTPS. Tested.
  2. I had to restart HA to get the integration back without error. (Even-though, after the change removing and adding back the NAS into the integration the errors were still there, without HA restart.)

zollak avatar May 11 '25 10:05 zollak

找不到路径

YXWHome avatar May 11 '25 10:05 YXWHome

Image

YXWHome avatar May 11 '25 10:05 YXWHome

@YXWHome I have written a step-by-step guide here: https://github.com/home-assistant/core/issues/144536#issuecomment-2869675049

zollak avatar May 11 '25 10:05 zollak

This also seems to fix the problem without having to ignore the Context Manager exception.

@contextmanager
def suppress_insecure_request_warning():
    import warnings
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', urllib3.exceptions.InsecureRequestWarning)
        yield

peternash avatar May 12 '25 14:05 peternash

Good morning. Today, day 15, I have updated to Core 2025.5.2 to see if the problem in ha with Qnap had solved. It has been very discouraging to verify that it persists, that it has not been solved. I keep the backup copies in QNAP and I am not sure what the consequences can be when I make copies again or when you want to recover them. I carry what is published on this site, in all three threads, Since the problem occurred and the truth is that because of my lack of knowledge I do not know how or when it is going to solve. My vision is surely too simple: something that worked, that is changed, I suppose that by mistake, and now it seems complicated to return to its place.

patxo avatar May 17 '25 07:05 patxo