-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
load accepts Sequence rather than Iterable (rejects generators) #2795
Conversation
ah, looks like this breaks handling of update: fixed |
this is ready for review. i thought this was a breaking change since it changes what we're accepting as valid input. but one could argue this is bugfix, since non-sequence inputs are silently failing to call schema validators. should this be backported to v3? |
Arguable. I don't really mind either way, but considering the move to v4 should be easy, I'm tempted to keep things as is in v3 and expect users to move fast to v4. Did we consider actually supporting generators? Is the rationale that this is costly to do in marshmallow so we prefer users unpack their generators themselves? |
we've never explicitly supported generators. the immediate rationale for this is that handling generators is currently broken but it fails silently (schema validators aren't called) |
Yes, I got that. Just wondering if we could solve this the other way by actually supporting the use case, and at what cost. This was investigated by @sirosen in #1898 (comment) and I don't think the downside he points to (post_load receives a list) is really an issue. |
gotcha. i'd rather avoid adding another runtime type-check, for the reason sirosen pointed out (pre_load wouldn't actually receive the "raw" input, which is pretty unintuitive) as well as the performance hit. |
My opinion circling back on this is that If you want to pass in a generator, you can make the decision between these two basic approaches:
I would say no (real) support is being lost, but that it's not important enough to be worth any extra work backporting to v3. That's just based on it being in this state for a few years and that issue getting relatively low traffic. Footnotes
|
Having different maybe this is reason enough to backport this to v3? wdyt @lafrech @sirosen |
I'm tied. There may be users in the wild passing generators who never got any issue because they don't use Since the move to v4 is easy, I figured I'd drop v3 in the same go in flask-smorest (unless it is zero effort to support both, which may be the case since there are no type hints in flask-smorest). I agree the workaround you had to come up with is a bit painful. Do you think many libraries are impacted? Looks like you didn't face this issue when updating webargs. EOLing MA3 soon after MA4 ships would help ensuring libraries move to v4 and drop v3 quickly. |
I haven't given it really deep thought, but I think I'm fine following either path. One thing about backporting the typing fix to v3 is that users have two viable workarounds until they're ready to jump to v4:
I think that's totally acceptable for a typing-only change. I can't imagine that we're going to want to make many more changes on v3 at all1, so I'm mostly looking at any changes to v3 as "things we should do to aid transition". I'm not sure this one is that significant? But I'm not against it by any means. Footnotes
|
IIUC, this is not a typing-only change. This actually prevents users from passing generators anymore. It works without this change, except for
|
@lafrech is correct; it's a bit more than a typing-only change. i'll hold off on backporting this for now. the workaround i had to do in ma-sqlalchemy isn't too bad and will only be needed in libraries that have a |
👍 yep, i'm thinking the same
i think supporting v3 for 3-6 months (bug fixes only) after the v4 release would be a reasonable timeline. most/all of the marshmallow-code libs are already supporting v4 now, so the maintenance burden for us should be relatively low. i want to give other popular ones like marshmallow-dataclass and airflow enough time to migrate. |
addresses #1898
Caveat: for some reason, mypy doesn't error when passing a generator. it seems that generators are covariant with
Sequence
and are therefore equivalent for type-checking purposes. not sure if there is a better way to handle this.