Skip to content

Conversation

@davidrapan
Copy link
Contributor

@davidrapan davidrapan commented Oct 27, 2025

Proposed change

Add support for aiomysql, aiosqlite and asyncpg drivers to:

  1. Provide fully asynchronous approach within HA and let SQLAlchemy handle it (optional) instead of wrapping sync calls to sync drivers using *.async_add_executor_job() on HA side:
    if self._use_database_executor:
    await get_instance(self.hass).async_add_executor_job(self._update)
    else:
    await self.hass.async_add_executor_job(self._update)
  2. As a testbed for possible future implementation in recorder as well

In the form of new async drivers:

+ greenlet through SQLAlchemy[asyncio] because asynchronous SQLAlchemy depends on it

And improves code coverage.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @gjohansson-ST, @dougiteixeira, mind taking a look at this pull request as it has been labeled with an integration (sql) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of sql can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign sql Removes the current integration label and assignees on the pull request, 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 pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@MartinHjelmare
Copy link
Member

Please explain in the PR description why you want to make this change.

@MartinHjelmare MartinHjelmare marked this pull request as draft October 27, 2025 11:12
Comment on lines +327 to +328
# https://github.com/aio-libs/aiomysql
"sql": {"homeassistant": {"aiomysql"}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't think it's a good idea to add a requirements exception.
This is used to track "existing" violations, not to enable new violations to come in.

Copy link
Contributor Author

@davidrapan davidrapan Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I do about

Error: R] [REQUIREMENTS] Package aiomysql has a forbidden top level directory 'docs' in homeassistant

during Check hassfest to handle it properly then?

Copy link
Contributor

@epenet epenet Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should raise an issue on aiomysql repository to ask them to remove the docs from the published package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.. okay. I'll do that then, thanks.

@davidrapan davidrapan force-pushed the sql-async_sqlalchemy branch 4 times, most recently from 6f2b976 to 381c25e Compare October 27, 2025 17:23
Signed-off-by: David Rapan <david@rapan.cz>
@davidrapan davidrapan force-pushed the sql-async_sqlalchemy branch from 381c25e to 7676e77 Compare October 28, 2025 14:46
@epenet
Copy link
Contributor

epenet commented Oct 28, 2025

Please stop rebasing unnecessarily, and do NOT merge commits.

  • If there is something new => add it as a new commit (it makes reviewing way easier)
  • If there is nothing new => just keep the PR as it is

@davidrapan
Copy link
Contributor Author

davidrapan commented Oct 28, 2025

I do it when I want to restart checks, usually. 😉

Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
Signed-off-by: David Rapan <david@rapan.cz>
@davidrapan davidrapan force-pushed the sql-async_sqlalchemy branch from e5a0385 to fd3e8e6 Compare October 29, 2025 21:56
Signed-off-by: David Rapan <david@rapan.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants