-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Unwrap django lazy objects in mutation resolvers #338
Unwrap django lazy objects in mutation resolvers #338
Conversation
The changes look great! Can we have a test for it? Just to avoid that from regressing in the future for whatever reason :) |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #338 +/- ##
==========================================
+ Coverage 87.87% 87.99% +0.12%
==========================================
Files 33 33
Lines 2935 2940 +5
==========================================
+ Hits 2579 2587 +8
+ Misses 356 353 -3
☔ View full report in Codecov by Sentry. |
931adfd
to
54069c4
Compare
@bellini666 I am not familiar with the pyright issues that are reported by the |
Indeed they are currently not your fault =P. It just happened to a new version of pyright to be released while this PR was opened, and it did have some regressions in our code which I fixed in aed240e You can ignore those or just merge/rebase on top of the current main branch. Btw, the PR is still marked as draft. Is there anything missing or can I review it? |
@ryanprobus taking a look at your PR, maybe some of the pyright issues are due to your PR. More specifically, the issues inside The reason is that |
Hi @ryanprobus , pyright still thinks that the instance. I checked out your branch and the issue is that the function itself is not typed (because the overloads are) You might want to change it from: @transaction.atomic
def update(
info,
instance,
data,
*,
full_clean: bool | FullCleanOptions = True,
pre_save_hook: Callable[[_M], None] | None = None,
): to: @transaction.atomic
def update(
info: Info,
instance: _M | Iterable[_M],
data: dict[str, Any],
*,
full_clean: bool | FullCleanOptions = True,
pre_save_hook: Callable[[_M], None] | None = None,
) -> _M | list[_M]: That should fix everything and IMO the patch is ready to be merged |
* Django lazy objects have a proxy __iter__ method that causes them to be considered iterables even if the wrapped object isn't. This causes errors when calling list on the lazy object. Avoid this by checking and unwrapping any lazy objects. A lazy object could be passed to these mutation resolvers if accessing the django request's user.
e0c740e
to
08a5f18
Compare
Hey @ryanprobus , I took the liberty of updating your PR and fixing the remaining typing issues. I removed its "Draft" status because I believe it is ready to be merged. Is there anything else missing in here? Or can I merge it as soon as the tests pass? |
@bellini666 Its all good to go if you it looks good to you. Thanks for taking a look at the pyright issues. |
Description
__iter__
method that causes them to be considered iterables even if the wrapped object isn't. This causes errors when calling list on the lazy object. Avoid this by checking and unwrapping any lazy objects. A lazy object could be passed to these mutation resolvers if accessing the django request's user.Types of Changes
Issues Fixed or Closed by This PR
Checklist