Skip to content

Conversation

@hjtran
Copy link
Contributor

@hjtran hjtran commented Jul 3, 2025

This is often a useful pattern but this warning makes it seem like a bug.

e.g. _PassThroughThenCleanup is an example where we have a dofn that doesn't return anything

@github-actions github-actions bot added the python label Jul 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2025

Assigning reviewers:

R: @damccorm for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

if lstripped_line.startswith(
"return None") or lstripped_line.rstrip() == "return":
_LOGGER.warning(return_none_warning)
if has_yield and has_return:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was a bit conservative with what I removed but I actually wonder if any of the warnings in this function are useful

@damccorm
Copy link
Contributor

damccorm commented Jul 7, 2025

R: @liferoad since this came out of #28061

I'm somewhat ambivalent about this one. I've seen issues where this warning has or would have helped. I've also seen people get confused by the wording.

Instead of removing the warning, could we clarify the text so that it is obvious that you can ignore it if it is intentional?

@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2025

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@hjtran
Copy link
Contributor Author

hjtran commented Jul 7, 2025

R: @liferoad since this came out of #28061

I'm somewhat ambivalent about this one. I've seen issues where this warning has or would have helped. I've also seen people get confused by the wording.

Instead of removing the warning, could we clarify the text so that it is obvious that you can ignore it if it is intentional?

It'd be nice if there was an easy way to discriminate between whether this case might be an accident or if it's actually intended. As it stands, I'm not sure there's an obvious way to silence this warning as a DoFn author who really doesn't want to yield anything (I suppose they can just yield and empty generator but I wouldn't call that obvious)

@liferoad
Copy link
Contributor

liferoad commented Jul 7, 2025

R: @liferoad since this came out of #28061
I'm somewhat ambivalent about this one. I've seen issues where this warning has or would have helped. I've also seen people get confused by the wording.
Instead of removing the warning, could we clarify the text so that it is obvious that you can ignore it if it is intentional?

It'd be nice if there was an easy way to discriminate between whether this case might be an accident or if it's actually intended. As it stands, I'm not sure there's an obvious way to silence this warning as a DoFn author who really doesn't want to yield anything (I suppose they can just yield and empty generator but I wouldn't call that obvious)

I would argue the good practice is to return something.

@hjtran
Copy link
Contributor Author

hjtran commented Jul 16, 2025

R: @liferoad since this came out of #28061
I'm somewhat ambivalent about this one. I've seen issues where this warning has or would have helped. I've also seen people get confused by the wording.
Instead of removing the warning, could we clarify the text so that it is obvious that you can ignore it if it is intentional?

It'd be nice if there was an easy way to discriminate between whether this case might be an accident or if it's actually intended. As it stands, I'm not sure there's an obvious way to silence this warning as a DoFn author who really doesn't want to yield anything (I suppose they can just yield and empty generator but I wouldn't call that obvious)

I would argue the good practice is to return something.

I think it might not be a very known good practice. I for one didnt realize it was good practice and have written a decent number of side effect transforms. These warnings also don't account for dofns that yield elements in finish_bundle or yield batches.

I tried turning the warning into an error to see which dofns currently don't yield anything and here's a partial list:

  • _BeamRowsToArrowTable
  • RemoveExtractedFiles
  • apache_beam.io.gcp.bigquery_file_loads.UpdateDestinationSchema'
  • apache_beam.io.mongodbio._WriteMongoFn
  • apache_beam.transforms.ptransform._AddMaterializationTransforms._materialize_transform.._MaterializeValuesDoFn
  • apache_beam.io.gcp.bigtableio._BigTableWriteFn
  • apache_beam.runners.direct.direct_runner._DirectWriteToPubSubFn
  • apache_beam.testing.test_stream._TestStreamFormatter
  • apache_beam.dataframe.convert.RowsToDataFrameFn

I think the noise-to-signal ratio might be high enough that the warnings get ignored.

@liferoad
Copy link
Contributor

I think the warning is still helpful but as suggested before, maybe we can rephrase the warning to be less alarming. WDYT?

@hjtran
Copy link
Contributor Author

hjtran commented Jul 17, 2025

I think the warning is still helpful but as suggested before, maybe we can rephrase the warning to be less alarming. WDYT?

For me it's less the phrasing and more seeing any warning at all. I typically try to investigate most warnings and these can pop up sometimes even for transforms that I didn't write.

If you think it's helpful though, I can just put in return [] for the transforms that I run into often though :)

Thanks for the discussion!

@hjtran hjtran closed this Jul 17, 2025
@Abacn
Copy link
Contributor

Abacn commented Oct 31, 2025

This warning message is spamming. As mentioned above, many internal DoFns falls into the category and will raise warnings. There are not actionable either. There is also a bug in the current warning message.

At least let us skip warning for internal variables.

@hjtran
Copy link
Contributor Author

hjtran commented Oct 31, 2025

It'd be really nice to just remove altogether, not just for internal transforms. Schrodinger transforms often raise this warning and I get a lot of questions about how to investigate and whether the user should be worried.

I think in a vast majority of cases, the user intent of "I don't want this DoFn to generate any outputs" is expressed by returning None in process (either explicitly or implicitly). The cases in which this was an accident (e.g. a user forgot to yield an output that they mean to output) will usually be discovered through other systems, like having a workflow that just doesn't generate anything when it obviously should.

@Abacn
Copy link
Contributor

Abacn commented Oct 31, 2025

Read the previous discussion there might be a case the warning is valid. Opened #36703 and explained there

@Abacn
Copy link
Contributor

Abacn commented Oct 31, 2025

I don't want this DoFn to generate any outputs" is expressed by returning None in process (either explicitly or implicitly).

Now suppressed warning for the case of a bare return, and only issue warning for return None. Because return None is confusingly equivalent to return and won't emit "None" downstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants