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 sneaky import cycle #974

Merged
merged 3 commits into from
Dec 18, 2021
Merged

Fix sneaky import cycle #974

merged 3 commits into from
Dec 18, 2021

Conversation

dairiki
Copy link
Contributor

@dairiki dairiki commented Dec 17, 2021

There is a sneaky import cycle that is exposed by running:

$ python -c "import lektor.types"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dairiki/git/web/lektor-packages/lektor/lektor/types/__init__.py", line 11, in <module>
    from lektor.types.multi import CheckboxesType
  File "/home/dairiki/git/web/lektor-packages/lektor/lektor/types/multi.py", line 4, in <module>
    from lektor.environment.expressions import Expression
  File "/home/dairiki/git/web/lektor-packages/lektor/lektor/environment/__init__.py", line 28, in <module>
    from lektor.types import builtin_types
ImportError: cannot import name 'builtin_types' from partially initialized module 'lektor.types' (most likely due to a circular import) (/home/dairiki/git/web/lektor-packages/lektor/lektor/types/__init__.py)

This is import-order dependent. If one imports lektor.environment before importing lektor.types all is well.

(It appears this cycle was introduced in 7c68f3f78.)

Description of Changes

  • Added a unit test that exercises the bug
  • Fixed the problem
  • Added unit test(s) covering the changes (if testable)

This excercises an tricky import cycle introduced in:

  7c68f3f more imports at top level
@dairiki dairiki marked this pull request as ready for review December 17, 2021 04:46
dairiki added a commit to dairiki/lektor-datetime-helpers that referenced this pull request Dec 17, 2021
dairiki added a commit to dairiki/lektor-datetime-helpers that referenced this pull request Dec 17, 2021
dairiki added a commit to dairiki/lektor-datetime-helpers that referenced this pull request Dec 17, 2021
@dairiki dairiki added the bug label Dec 17, 2021
Copy link
Contributor

@yagebu yagebu left a comment

Choose a reason for hiding this comment

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

Good catch and that test is very good to have :)

@yagebu yagebu merged commit 2e06c93 into lektor:master Dec 18, 2021
@dairiki dairiki deleted the bug.import-cycle branch December 18, 2021 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants