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: move BlockKey and derived_key to avoid cyclical import #34051

Merged
merged 2 commits into from
Jan 16, 2024

Commits on Jan 16, 2024

  1. fix: move BlockKey and derived_key to avoid cyclical import

    After we merged this PR: openedx#33920
    this error began popping up in logs:
    
        Unable to load XBlock 'staffgradedxblock'
        ....
        ImportError: cannot import name 'get_course_blocks' from
        partially initialized module 'lms.djangoapps.course_blocks.api'
        (most likely due to a circular import) ...
    
    The root cause was the new imports of `derived_key` and `BlockKey` into
    xmodule/library_content_block.py. Those new imports come from
    xmodule/modulestore/store_utilities.py, which runs
    `XBlock.load_classes()` at the module level, which fails because we are
    still in the process of loading xmodule/library_content_block.
    
    As a solution, we move both `derived_key` and `BlockKey` to
    xmodule/util/keys.py. We could potentially move that file to opaque-keys
    eventually, depending on how well we think that those concepts generalize.
    
    Also:
    
    * We rename the function from derived_key to derive_key, as
      functions should be verbs.
    * We combine the first to parameters of derive_key (a source ContextKey
      and a source BlockKey) into a single parameter (a source UsageKey). In
      my opinion, this makes the function call easier to understand.
    kdmccormick committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    e064bf9 View commit details
    Browse the repository at this point in the history
  2. fix: in generate_block_key, get the usage key's block_id, not usage_id

    UsageKeys don't have a usage_id field. This line would have crashed
    if run.
    kdmccormick committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    0f86d30 View commit details
    Browse the repository at this point in the history