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

Warning: Integration accesses the database without the database executor #127

Closed
AdmiralStipe opened this issue Apr 6, 2022 · 13 comments
Closed
Labels
bug Something isn't working.

Comments

@AdmiralStipe
Copy link

AdmiralStipe commented Apr 6, 2022

Environment

  • Home Assistant Core release with the issue: 2022.4.0
  • This custom component release with the issue: 2.2.1
  • Last working this custom component release (if known):
  • Operating environment (Home Assistant/Supervisor/Docker/venv): HA Supervised

Describe the bug

With the latest HA update (2022.4.0) the warnings about writing to database related to "Average integration" started appearing in my log with instruction, to notify the author about it (see log below).

Configuration.yaml

Steps to Reproduce

Update to latest HA version

Expected behavior

Debug log


2022-04-06 22:03:51 WARNING (SyncWorker_6) [homeassistant.helpers.frame] Detected integration that accesses the database without the database executor; Use homeassistant.components.recorder.get_instance(hass).async_add_executor_job() for faster database operations. Please report issue to the custom component author for average using this method at custom_components/average/sensor.py, line 477: history_list = history.state_changes_during_period(

2022-04-06 22:18:47 WARNING (SyncWorker_5) [homeassistant.helpers.frame] Detected integration that accesses the database without the database executor; Use homeassistant.components.recorder.get_instance(hass).async_add_executor_job() for faster database operations. Please report issue to the custom component author for average using this method at custom_components/average/sensor.py, line 491: item = history.get_state(self.hass, start, entity_id)




Logger: homeassistant.helpers.frame
Source: helpers/frame.py:103
First occurred: 22:03:51 (2 occurrences)
Last logged: 22:18:47

Detected integration that accesses the database without the database executor; Use homeassistant.components.recorder.get_instance(hass).async_add_executor_job() for faster database operations. Please report issue to the custom component author for average using this method at custom_components/average/sensor.py, line 477: history_list = history.state_changes_during_period(
Detected integration that accesses the database without the database executor; Use homeassistant.components.recorder.get_instance(hass).async_add_executor_job() for faster database operations. Please report issue to the custom component author for average using this method at custom_components/average/sensor.py, line 491: item = history.get_state(self.hass, start, entity_id)

Additional context

@AdmiralStipe AdmiralStipe added the bug Something isn't working. label Apr 6, 2022
@Jurgenn22
Copy link

@Limych i got the Same warning in logs.

@faduchesne
Copy link

same Problem for me

@markus99
Copy link

Same upon upgrade to 2022.4.6

Detected integration that accesses the database without the database executor; Use homeassistant.components.recorder.get_instance(hass).async_add_executor_job() for faster database operations. Please report issue to the custom component author for average using this method at custom_components/average/sensor.py, line 477: history_list = history.state_changes_during_period(

@ippo112
Copy link

ippo112 commented Apr 26, 2022

same for me.


System Health

version core-2022.4.7
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.9.9
os_name Linux
os_version 5.10.108
arch x86_64
timezone Europe/Rome

@lmagyar
Copy link
Contributor

lmagyar commented May 7, 2022

FYI: I've used this component with even debug level logging yesterday, and there weren't any warnings about this issue.
My config is slightly different (see below). And I'm using MariaDB as SQL backend.

Version core-2022.5.2
Installation Type Home Assistant OS
Development false
Supervisor true
Docker true
User root
Virtual Environment false
Python Version 3.9.9
Operating System Family Linux
Operating System Version 5.10.103-v7
CPU Architecture armv7l
Timezone Europe/Budapest

@Murianwind
Copy link

Logger: homeassistant.helpers.frame
Source: helpers/frame.py:103
First occurred: 05:25:13 (1 occurrences)
Last logged: 05:25:13

Detected integration that accesses the database without the database executor; Use homeassistant.components.recorder.get_instance(hass).async_add_executor_job() for faster database operations. Please report issue to the custom component author for average using this method at custom_components/average/sensor.py, line 477: history_list = history.state_changes_during_period(

@bdraco
Copy link

bdraco commented May 8, 2022

Accessing the database from the event loop will raise an exception in 2022.6 since it causes instability by blocking Home Assistant's event loop (which means it cannot do anything until the database call finishes): home-assistant/core#71547

It looks like https://github.com/Limych/ha-average/blob/dev/custom_components/average/sensor.py#L219 should not be decorated with @callback and instead should be a coroutine that calls homeassistant.components.recorder.get_instance(hass).async_add_executor_job(self._update_state)

https://github.com/Limych/ha-average/blob/dev/custom_components/average/sensor.py#L296 should be changed to async_update and call homeassistant.components.recorder.get_instance(hass).async_add_executor_job(self._update_state) as well

@DavidFW1960
Copy link

@Limych did you see Nick's post above?

@ACrazyConcept
Copy link

ACrazyConcept commented May 9, 2022

@bdraco can you post the whole code snippets for those two functions?

@dcf1999
Copy link

dcf1999 commented May 11, 2022

@bdraco Updating those lines caused a slew of errors when I "checked configuration". It did let me restart and after restart, sensor still inop

@Limych Limych closed this as completed in 5e3f1ad May 22, 2022
@bdraco
Copy link

bdraco commented May 22, 2022

Looks like it's sorted now. It could likely be optimized further by calling self.async_write_ha_state() in async_sensor_state_listener instead of scheduling another update unless there is a new to do another update but it should work just fine 👍

@markus99
Copy link

markus99 commented Oct 11, 2022 via email

@lmagyar
Copy link
Contributor

lmagyar commented Oct 11, 2022

Statistics sensor doc says: "The statistics sensor updates with every source sensor update." It's the same behavior as the filter sensors, that produces constant wrong values: off by 1 precision nearly all the time, see #26. :(

Correct me if I'm wrong or things changed in HA in the past year.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests