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

docs: [FC-0074] add suggestion about the design of filters #240

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mariajgrimaldi
Copy link
Member

@mariajgrimaldi mariajgrimaldi commented Dec 20, 2024

Description

This PR adds an ADR with practices to consider when designing a filter and contributing it back to the library to be maintained as part of the framework. I'm proposing that these practices be considered when implementing new filters, but they should NOT be considered standards that all filters should strictly follow. Also, I'm not saying either that all the existing filters in the library comply (or should) with these practices.

This document will be used as a reference in the How to Create a New Filter guide. I'm currently validating these items while I write the guide, making sure these suggestions are clear enough to follow. You can review it here (consider that is still a draft): #242

Testing instructions

You can review the docs here: https://docsopenedxorg--240.org.readthedocs.build/projects/openedx-filters/en/240/decisions/0007-filter-design-practices.html

Deadline

None

Checklists

Check off if complete or not applicable:

Merge Checklist:

  • All reviewers approved
  • Reviewer tested the code following the testing instructions
  • CI build is green
  • Version bumped
  • Changelog record added with short description of the change and current date
  • Documentation updated (not only docstrings)
  • Code dependencies reviewed
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

Post Merge:

  • Create a tag
  • Create a release on GitHub
  • Check new version is pushed to PyPI after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)
  • Upgrade the package in the Open edX platform requirements (if applicable)

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 20, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Dec 20, 2024

Thanks for the pull request, @mariajgrimaldi!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/hooks-extension-framework. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Dec 20, 2024
@mariajgrimaldi mariajgrimaldi force-pushed the MJG/practices-suggestions-adr branch from 0ea79df to e8816cd Compare December 25, 2024 12:25
@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review December 26, 2024 08:48
@mariajgrimaldi mariajgrimaldi requested a review from a team as a code owner December 26, 2024 08:48
@MaferMazu
Copy link

I like this PR.

I would suggest adding a code example to show how to apply the guidelines correctly. It could be a full example or an example for each section.

It is not a blocker, but I think it could improve the understanding of the guidelines. Also, we are referencing this ADR in the how-to documentation. What do you think @mariajgrimaldi?

Example:

Design Clarity and Understanding

  • A filter should describe as accurately as possible what behavior intends to modify.
  • A filter should have a clear and concise name that describes its purpose.
  • Ensure that the triggering logic of the filter is consistent and narrow. It should only trigger when the conditions are met and cover all the cases that the filter should be applied with the minimum number of modifications.

Anti-pattern

# openedx-filters
class CertificateFilter(OpenEdxPublicFilter):
    """
    Custom class used to create certificate creation filters and its custom methods.
    """

Best practice

# openedx-filters
class CertificateCreationRequested(OpenEdxPublicFilter):
    """
    Custom class used to create certificate creation filters and its custom methods.
    """
# edx-platform
def _generate_certificate_task(user, course_key, enrollment_mode, course_grade, status=None, generation_mode=None,
                               delay_seconds=CERTIFICATE_DELAY_SECONDS):
    """
    Create a task to generate a certificate
    """
    log.info(f'About to create a regular certificate task for {user.id} : {course_key}')

    course_grade_val = _get_grade_value(course_grade)

    try:
        # .. filter_implemented_name: CertificateCreationRequested
        # .. filter_type: org.openedx.learning.certificate.creation.requested.v1
        user, course_key, enrollment_mode, status, course_grade, generation_mode = CertificateCreationRequested.run_filter(  # pylint: disable=line-too-long
            user=user,
            course_key=course_key,
            mode=enrollment_mode,
            status=status,
            grade=course_grade,
            generation_mode=generation_mode,
        )
    except CertificateCreationRequested.PreventCertificateCreation as exc:
        raise CertificateGenerationNotAllowed(str(exc)) from exc

@mariajgrimaldi
Copy link
Member Author

mariajgrimaldi commented Dec 30, 2024

@MaferMazu: That's a really good idea! I'll work on integrating some examples in the ADR independently from the how-to. I'll ping you once it's done. Thank you!

@mariajgrimaldi
Copy link
Member Author

@MaferMazu: done, you can review the changes now. Thank you again for the suggestions!

@MaferMazu
Copy link

I think it would be better if we had the general example with his own section and referenced it in the guidelines that need a reference so as not to stick to the general example only in the first suggestion and have to return to that in the next ones. What do you think @mariajgrimaldi?

@mariajgrimaldi
Copy link
Member Author

@MaferMazu: I'm not sure I understand your latest comment. Could you explain a bit further? Thanks for the patience!

@MaferMazu
Copy link

MaferMazu commented Jan 7, 2025

I proposed having a specific section for the example because, right now, it is inside one of the recommendations, and returning a particular recommendation to view the example doesn't seem in order.

Right now, we have the following:

Design Clarity and Understanding
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
<Example>

Contextual Information
~~~~~~~~~~~~~~~~~~~~~~
...
Consider the user login filter example above. The filter provides...

...

Error Handling
~~~~~~~~~~~~~~
...
Consider the user login filter example above...

The idea is to have something like:

Design Clarity and Understanding
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
Consider the `Example with Best Practices`_  ...

Contextual Information
~~~~~~~~~~~~~~~~~~~~~~
...
Consider the `Example with Best Practices`_ . The filter provides...

...

Example with Best Practices
~~~~~~~~~~~~~~~~~~~~~~~~
<Example>

Or having the example above.

The main idea is not to have the whole example we want to reference in a particular guideline.

In my first suggestion, I thought of an example for each section that needed it. But if we use one example as a reference throughout the document, it makes sense that it has its section and doesn't live in a particular one.

@mariajgrimaldi
Copy link
Member Author

mariajgrimaldi commented Jan 8, 2025

@MaferMazu: Thank you for the detailed explanation. However, I think adding a more detailed example here would remove the need for this PR to implement a filter that follows these practices. Do you think we'd still need the example having that how-to?

Copy link

@MaferMazu MaferMazu left a comment

Choose a reason for hiding this comment

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

My comment was about the location of the example, and you already addressed it.

This looks good to me. Thanks @mariajgrimaldi

Copy link
Member

@felipemontoya felipemontoya left a comment

Choose a reason for hiding this comment

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

I think the advice contained in this doc is solid and at the technical level everything looks correct to me.

Feel free to merge when the inlines are addressed.

docs/decisions/0007-filter-design-practices.rst Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

6 participants