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

Fix flaky statistics sensor test #21848

merged 1 commit into from Mar 9, 2019


None yet
3 participants
Copy link

commented Mar 9, 2019


I am not an expert of sqlalchemy, but the logic of the session_scope seems weird to me.

Hope it can fix the error we randomly saw in python 3.5 test

ERROR:homeassistant.components.recorder.util:Error executing query: (sqlite3.OperationalError) cannot commit - no transaction is active (Background on this error at:
ERROR:homeassistant.core:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 753, in _commit_impl
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 489, in do_commit
sqlite3.OperationalError: cannot commit - no transaction is active
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/opt/python/3.5.3/lib/python3.5/asyncio/", line 239, in _step
    result = coro.send(None)
  File "/home/travis/build/home-assistant/home-assistant/homeassistant/components/sensor/", line 293, in _async_initialize_from_database
    states = execute(query)
  File "/opt/python/3.5.3/lib/python3.5/", line 66, in __exit__
  File "/home/travis/build/home-assistant/home-assistant/homeassistant/components/recorder/", line 25, in session_scope
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/orm/", line 1023, in commit
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/orm/", line 491, in commit
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 1708, in commit
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 1739, in _do_commit
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 755, in _commit_impl
    self._handle_dbapi_exception(e, None, None, None, None)
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 1458, in _handle_dbapi_exception
    util.raise_from_cause(sqlalchemy_exception, exc_info)
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/util/", line 296, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/util/", line 276, in reraise
    raise value.with_traceback(tb)
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 753, in _commit_impl
  File "/home/travis/build/home-assistant/home-assistant/.tox/cov/lib/python3.5/site-packages/sqlalchemy/engine/", line 489, in do_commit
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) cannot commit - no transaction is active (Background on this error at:

Related issue (if applicable): fixes #

Pull request in with documentation (if applicable): home-assistant/< PR number goes here>

Example entry for configuration.yaml (if applicable):


  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

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

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

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@ghost ghost assigned awarecan Mar 9, 2019

@ghost ghost added the in progress label Mar 9, 2019

@balloob balloob merged commit 226be65 into home-assistant:dev Mar 9, 2019

4 checks passed

Hound No violations found. Woof!
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
coverage/coveralls Coverage increased (+0.0006%) to 92.724%

@ghost ghost removed the in progress label Mar 9, 2019

@awarecan awarecan deleted the awarecan:fix-flaky-test branch Mar 9, 2019

mxworm added a commit to mxworm/home-assistant that referenced this pull request Mar 9, 2019

Merge branch 'dev' into current
* dev: (82 commits)
  Add ClearPass Policy Manger device tracker (home-assistant#21673)
  Better cloud check (home-assistant#21875)
  Bump quirks for ZHA and handle resulting battery % change (home-assistant#21869)
  Only commit if need. (home-assistant#21848)
  Fix authorization header in cors (home-assistant#21662)
  Introduce Entity.async_write_ha_state() to not miss state transition (home-assistant#21590)
  Fix TypeError (home-assistant#21734)
  Update to read current humidity for US Thermostats (home-assistant#21728)
  Override http.trusted_networks by auth_provider.trusted_networks (home-assistant#21844)
  mobile_app improvements (home-assistant#21607)
  Fixed a misspelling in a docstring (home-assistant#21846)
  Update dependencies to receive data on webhook callbacks (home-assistant#21838)
  Fix config entry exception in Ambient PWS (home-assistant#21836)
  Updated to pyeconet 0.0.10 (home-assistant#21837)
  fix empty TOPIC_BASE issue (home-assistant#21740)
  Synology sensor quick return if attr is null (home-assistant#21709)
  Add support for Cisco Mobility Express (home-assistant#21531)
  Log if aiohttp hits error during IndieAuth (home-assistant#21780)
  Resolve auth_store loading race condition (home-assistant#21794)
  Load logger and system_log components as soon as possible (home-assistant#21799)

@balloob balloob referenced this pull request Mar 20, 2019


0.90.0 #22216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.