-
Notifications
You must be signed in to change notification settings - Fork 23
fix: return correct taxonomy depth up to max depth #507
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
Open
jesperhodge
wants to merge
6
commits into
openedx:main
Choose a base branch
from
jesperhodge:jhodge/fix--taxonomy-depth--independent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−24
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4fb8da4
fix: return correct taxonomy depth up to max depth
jesperhodge 4026567
refactor: make query readable
jesperhodge b58ba70
fix: lint
jesperhodge 8605ab7
fix: types
jesperhodge 3527655
fix: tests
jesperhodge 029a7eb
refactor: PR comment
jesperhodge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression here is that the
TAXONOMY_MAX_DEPTHconstant means that no APIs should ever return more than 3 levels deep at once, which is what was happening here. Now theget_filtered_tags()API is returning 4 levels deep, which violates the constant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this at first too, but
max_depthis zero-indexed.A tag's depth at root or first level is 0. A tag's depth at third level is 2, and at 4th level is 3. It is an explicit attribute in the data returned by the API. So we have a max depth of 3, but max levels of 4.
Many of the tests and code explicitly refer to
great-grandchildren, which are 4 levels deep, and the logic in other places always expects 4 max levels. For example,openedx-core/src/openedx_tagging/models/base.py
Line 493 in 62c937e
I assume the test comment was added due to a similar misunderstanding.
This inconsistency meant that you can create tags 4 levels deep - including when you import taxonomies and such - but then just cut off the deepest level, not displaying it, thus misleading the viewer.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code, as I see now, deals with taxonomies that may be more deeply nested (because of taxonomy imports). But it annotates taxonomy tags with a depth, which is "collapsed" to 5 levels.
Parts of the code expect the resulting taxonomy the API returns to have up to 5 levels, parts of the code expect it to have up to 4 levels, and parts of the code expect it to have up to 3.
This PR fixes the returned taxonomy not to cut tags off below the 3rd level, but below the 4th level, because that is what is defined by TAXONOMY_MAX_DEPTH.
Here is the code that sets the depth levels.
openedx-core/src/openedx_tagging/models/base.py
Line 150 in 62c937e
This makes it even worse:
TAXONOMY_MAX_DEPTHinsufficient.However I consider this part of the bug out of scope for this PR.
(Maybe the method linked here should better say
... default=TAXONOMY_MAX_DEPTH?), rolling everything up to 4 levels instead of 5?