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 circular import of config_validation and template #41802

Merged
merged 3 commits into from
Nov 5, 2020

Conversation

palfrey
Copy link
Contributor

@palfrey palfrey commented Oct 13, 2020

Proposed change

Correct circular imports of config_validation. Without this fix the following occurs:

>>> from homeassistant.components.http import HomeAssistantView
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/palfrey/src/home-assistant-core/homeassistant/components/http/__init__.py", line 20, in <module>
    from homeassistant.helpers import storage
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/storage.py", line 10, in <module>
    from homeassistant.helpers.event import async_call_later
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/event.py", line 47, in <module>
    from homeassistant.helpers.template import RenderInfo, Template, result_as_boolean
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/template.py", line 35, in <module>
    from homeassistant.helpers import config_validation as cv, location as loc_helper
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/config_validation.py", line 519, in <module>
    def template(value: Optional[Any]) -> template_helper.Template:
AttributeError: partially initialized module 'homeassistant.helpers.template' has no attribute 'Template' (most likely due to a circular import)

So you fix the config_validation.py error, and then get the following in location.py

>>> from homeassistant.components.http import HomeAssistantView
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/palfrey/src/home-assistant-core/homeassistant/components/http/__init__.py", line 20, in <module>
    from homeassistant.helpers import storage
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/storage.py", line 10, in <module>
    from homeassistant.helpers.event import async_call_later
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/event.py", line 47, in <module>
    from homeassistant.helpers.template import RenderInfo, Template, result_as_boolean
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/template.py", line 35, in <module>
    from homeassistant.helpers import location as loc_helper
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/location.py", line 10, in <module>
    import homeassistant.helpers.config_validation as cv
  File "/home/palfrey/src/home-assistant-core/homeassistant/helpers/config_validation.py", line 519, in <module>
    def template(value: Optional[Any]) -> template_helper.Template:
AttributeError: partially initialized module 'homeassistant.helpers.template' has no attribute 'Template' (most likely due to a circular import)

After this fix:

>>> from homeassistant.components.http import HomeAssistantView
>>>

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)
  • 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:

Checklist

  • 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
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@homeassistant
Copy link
Contributor

Hi @palfrey,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Verified the circular import exists. That makes testing more difficult.

Would you please fix the merge conflict.

@palfrey
Copy link
Contributor Author

palfrey commented Oct 31, 2020

Would you please fix the merge conflict.

Done

@bdraco
Copy link
Member

bdraco commented Nov 2, 2020

confirmed its fixed

>>> import homeassistant.helpers.template
>>> 

@bdraco
Copy link
Member

bdraco commented Nov 5, 2020

Looks like this fixes the HACS CI as well 👍

Traceback (most recent call last):
  File "/hacs/action.py", line 10, in <module>
    from custom_components.hacs.hacsbase.configuration import Configuration
  File "/hacs/custom_components/hacs/__init__.py", line 13, in <module>
    from .operational.setup import (
  File "/hacs/custom_components/hacs/operational/setup.py", line 8, in <module>
    from homeassistant.helpers.event import async_call_later
  File "/usr/lib/python3.8/site-packages/homeassistant/helpers/event.py", line 48, in <module>
    from homeassistant.helpers.template import RenderInfo, Template, result_as_boolean
  File "/usr/lib/python3.8/site-packages/homeassistant/helpers/template.py", line 34, in <module>
    from homeassistant.helpers import config_validation as cv, location as loc_helper
  File "/usr/lib/python3.8/site-packages/homeassistant/helpers/config_validation.py", line 534, in <module>
    def template(value: Optional[Any]) -> template_helper.Template:
AttributeError: partially initialized module 'homeassistant.helpers.template' has no attribute 'Template' (most likely due to a circular import)

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