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

Update mutations.py to include full_clean parameter #701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keithhackbarth
Copy link
Contributor

@keithhackbarth keithhackbarth commented Feb 7, 2025

This is a draft PR. Just looking for feedback.

We would like to control if clean is called. Correctly, it looks like the only option on the field but the mutation wrapper is missing the parameter. This change simply adds the parameter.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Enhancements:

  • Allow controlling whether the clean method is called on mutations.

Copy link
Contributor

sourcery-ai bot commented Feb 7, 2025

Reviewer's Guide by Sourcery

This pull request enhances the mutation functions by adding a full_clean parameter to control the invocation of the clean method. The changes involve updating the function signatures and ensuring the new parameter is correctly passed to the underlying mutation calls.

Updated Class Diagram for Django Mutation Functions

classDiagram
    %% The mutation functions now include the new full_clean parameter

    class create {
      +extensions: list[FieldExtension]
      +argument_name: Optional[str]
      +handle_django_errors: Optional[bool]
      +full_clean: bool | FullCleanOptions = True
    }

    class update {
      +argument_name: Optional[str]
      +handle_django_errors: Optional[bool]
      +key_attr: Optional[str]
      +full_clean: bool | FullCleanOptions = True
    }

    class delete {
      +argument_name: Optional[str]
      +handle_django_errors: Optional[bool]
      +key_attr: Optional[str]
      +full_clean: bool | FullCleanOptions = True
    }

    %% Notes indicating the enhancement
    note for create "Added full_clean parameter to control invocation of clean method"
    note for update "Added full_clean parameter to control invocation of clean method"
    note for delete "Added full_clean parameter to control invocation of clean method"
Loading

File-Level Changes

Change Details Files
Added support for the full_clean parameter in mutation functions.
  • Imported FullCleanOptions from the types module.
  • Updated the create function to include a full_clean parameter with a default value and passed it to the Django mutation wrapper.
  • Updated the update function in a similar fashion by adding the full_clean parameter and propagating it to the inner function call.
  • Updated the delete function by introducing the full_clean parameter and ensuring it is forwarded appropriately.
strawberry_django/mutations/mutations.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @keithhackbarth - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -257,6 +258,7 @@
extensions: list[FieldExtension] = (), # type: ignore
argument_name: Optional[str] = None,
handle_django_errors: Optional[bool] = None,
full_clean: bool | FullCleanOptions = True,
) -> Any:
"""Create mutation for django input fields.
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider documenting the purpose and behavior of the full_clean parameter, particularly the FullCleanOptions variant.

The parameter's ability to accept both boolean and FullCleanOptions suggests important functionality that should be explained in the docstring.

Suggested change
"""Create mutation for django input fields.
"""Create mutation for django input fields.
Args:
full_clean: Controls model validation behavior before saving.
When True (default), performs standard Django model validation.
When False, skips validation.
When FullCleanOptions is provided, allows fine-grained control over validation:
- exclude: List of fields to exclude from validation
- validate_unique: Whether to validate model uniqueness constraints
- validate_constraints: Whether to validate model constraints
"""

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.08%. Comparing base (e9a5e11) to head (8dcbc47).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #701      +/-   ##
==========================================
- Coverage   88.36%   88.08%   -0.29%     
==========================================
  Files          42       42              
  Lines        3850     3851       +1     
==========================================
- Hits         3402     3392      -10     
- Misses        448      459      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bellini666
Copy link
Member

Hey @keithhackbarth ,

We would like to control if clean is called. Correctly, it looks like the only option on the field but the mutation wrapper is missing the parameter. This change simply adds the parameter.

I think this change is ok! TBH, not sure why we were not exposing those in first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants