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

Allow custom Taxonomy, ObjectTag subclasses to customize tagging behavior #62

Merged
merged 14 commits into from
Jul 20, 2023

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Jul 5, 2023

Description

Adds fields and methods to Taxonomy to support use of Taxonomy subclasses to customize tagging behavior, e.g. when returning the list of available tags. Ensures that Taxonomy instances returned from the API are cast where possible, and makes it easier for these subclasses to be used.

Also adds support for ObjectTag subclasses via cast and copy methods, however full use of this must be handled by the implementing API -- here in oel_tagging, we just assume ObjectTag.

  • Adds Taxonomy._taxonomy_class field to store the Taxonomy subclass that should be used to instantiate this instance.
  • Adds methods to Taxonomy to customize ObjectTag validation based on taxonomy, tag, and object fields, to make it easier for Taxonomy subclasses to validate the parts they care about.
  • Adds fields to Taxonomy for use by the system taxonomies being created: system_defined, and visible_to_authors.

Supporting information

Part of openedx/modular-learning#63, addresses openedx/edx-platform#32518 (comment)

Testing instructions

Manual testing is possible but not very useful, since we don't yet have views for these models and APIs.

But you can check that the added tests cover the expected polymorphism behavior supported by this change, and that tests are still covering 100% of the openedx_tagging module.

Other information

See openedx/edx-platform#32661 for this branch's use with content tagging.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jul 5, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Jul 5, 2023

Thanks for the pull request, @pomegranited! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

so that system taxonomies can store this field and ensure no one edits them.
allowing ObjectTags to be subclassed to validate themselves with
different taxonomies.
@pomegranited pomegranited force-pushed the jill/smarter-object-tags-rebase branch from 4c34a54 to bf6d6c2 Compare July 5, 2023 23:29
for completeness.
so that the various object tag classes can register themselves as
candidates for casting/resyncing ObjectTags.

* Updates tests to ensure full coverage for this change
* Updates Tag model to cascade delete if the Taxonomy or parent Tag is deleted.
  Fixes an oversight in the data model.
@pomegranited pomegranited force-pushed the jill/smarter-object-tags-rebase branch from bf6d6c2 to 926a8d3 Compare July 6, 2023 03:59
@ChrisChV
Copy link
Contributor

ChrisChV commented Jul 6, 2023

We can do this by assigning a custom ObjectTag subclass to each system taxonomy,
and using the ObjectTag class to return candidate tags with get_tags / autocompleted tags instead of using Taxonomy.

👍 to this. Yes, some system defined taxonomies need to overwrite get_tags

@ChrisChV
Copy link
Contributor

ChrisChV commented Jul 6, 2023

@pomegranited In systems-defined taxonomies, one more field is necessary: ​​visible. Maybe we can add that field in the Taxonomy class? Now I have no idea how to handle that in a subclass

@pomegranited pomegranited marked this pull request as ready for review July 10, 2023 05:05
@pomegranited pomegranited changed the title refactor: moves validation to ObjectTag and subclasses #2 Use custom ObjectTag subclasses to customize tagging behavior Jul 10, 2023
* system_defined cannot be set with api.create_taxonomy, and is not
  editable once set.
* adds taxonomy.visible_to_authors, which can be set to False for fully
  automated tagging.
to allow subclasses to be registered wherever they want to be.
@pomegranited pomegranited force-pushed the jill/smarter-object-tags-rebase branch from f260ddd to 9d07be9 Compare July 10, 2023 07:06
@pomegranited pomegranited force-pushed the jill/smarter-object-tags-rebase branch from 9d07be9 to a8566d3 Compare July 10, 2023 07:29
pomegranited added a commit to open-craft/edx-platform that referenced this pull request Jul 10, 2023
@ChrisChV
Copy link
Contributor

@pomegranited Looks good 👍

  • I tested this by running the tests.
  • I read through the code and tests with care

@pomegranited
Copy link
Contributor Author

pomegranited commented Jul 12, 2023

Hi @ormsbee CC @bradenmacdonald This and openedx/edx-platform#32661 are ready for your eyes :)

* uses the (overwritable) is_valid method instead of the (difficult to override) class method valid_for
* moves cast_object_tag to the registry, since we had to cast ObjectTags to do ^
* removes ObjectTag base class from the registry, so we can still use cast_object_tag for validation
and removes the Closed vs Open ObjectTag subclasses, and registry.

Tests are passing, but coverage isn't at 100%
@pomegranited pomegranited changed the title Use custom ObjectTag subclasses to customize tagging behavior Allow custom Taxonomy, ObjectTag subclasses to customize tagging behavior Jul 18, 2023
@pomegranited pomegranited force-pushed the jill/smarter-object-tags-rebase branch from c4f5cc7 to a7661bb Compare July 18, 2023 06:12
* adds optional taxonomy_class property+field to Taxonomy
* adds Taxonomy cast() method to use this class
* oel_tagging.api uses Taxonomy.cast() whenever practical
* moves ObjectTag validation back to Taxonomy
* removes ObjectTag.resync() logic -- we don't need it yet.
* removes ObjectTag.object_type field -- we're not using it for anything.
* squashes migrations from previous commits
* reduces diff
@pomegranited pomegranited force-pushed the jill/smarter-object-tags-rebase branch from a7661bb to 0807949 Compare July 18, 2023 07:21
pomegranited added a commit to open-craft/edx-platform that referenced this pull request Jul 18, 2023
* adds ContentTaxonomy and ContentTag proxy models
* updates api to create/return ContentTaxonomy and ContentTag models
* other updates to align with changes to openedx/openedx-learning#62
* fixes linting & test coverage
docs/decisions/0007-tagging-app.rst Outdated Show resolved Hide resolved
openedx_tagging/core/tagging/models.py Outdated Show resolved Hide resolved
openedx_tagging/core/tagging/models.py Outdated Show resolved Hide resolved
openedx_tagging/core/tagging/models.py Outdated Show resolved Hide resolved
Subclasses can override this method to perform their own validation checks, e.g. against dynamically generated
tag lists.
Subclasses should override the internal _validate* methods to perform their own validation checks, e.g. against
dynamically generated tag lists.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to have a fully dynamic taxonomy (perhaps prime numbers or fibonacci numbers, something like that) in the test suite here. That can come in a follow-up PR though, based on learnings from the system taxonomies PR.

Copy link
Contributor Author

@pomegranited pomegranited Jul 19, 2023

Choose a reason for hiding this comment

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

Yep, good idea. @ChrisChV is there time/space to cover this test case as part of your system taxonomy PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I will keep that in mind now that I make the changes in my PR

also updates some docs as per PR review.
@bradenmacdonald
Copy link
Contributor

Thanks @ormsbee. Could you please hit merge on this? It seems I don't have permission and I'm not sure who else does.

@ormsbee
Copy link
Contributor

ormsbee commented Jul 19, 2023

@pomegranited has permissions. Do you mind if I wait for her to come on so that she can squash as she deems appropriate?

Also, 🤦 that I didn't put up a thread to expand your permissions to include this repo. I'll just do that now...

@bradenmacdonald
Copy link
Contributor

@ormsbee Ah ok that's great 👍🏻 Thanks!

@pomegranited
Copy link
Contributor Author

Huge thank you @bradenmacdonald , @ChrisChV and @ormsbee ! I think retaining the discussions here is important for this PR, but I don't want to muddy the main branch, so will squash + merge now.

@pomegranited pomegranited merged commit f5164bb into openedx:main Jul 20, 2023
5 checks passed
@openedx-webhooks
Copy link

@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants