[Platform] Make DeferredResult and RawHttpResult safe to dump()/dd() - #2501
Conversation
|
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
chr-hertel
left a comment
There was a problem hiding this comment.
Nice idea, thanks @alireza-aminzadeh! Haven't tested it yet, but I think for the DeferredResult it would be nice to keep more of the instance's state, e.g. error message, metadata, options
733d81e to
d962cda
Compare
|
Thanks for the feedback! Pushed a commit that extends
Also widened the Rebased on the latest |
| default => 'pending', | ||
| }, | ||
| 'options' => $this->options, | ||
| 'metadata' => $this->getMetadata()->all(), |
There was a problem hiding this comment.
just realizing that the API design here is not that great because the getMetadata() has the side-effect of creating metadata if not existing. usually not an issue, but maybe misleading while debugging.
how about:
| 'metadata' => $this->getMetadata()->all(), | |
| 'metadata' => $this->metadata?->all(), |
keeps the state more honest
chr-hertel
left a comment
There was a problem hiding this comment.
Will patch that minor finding while merging - thanks @alireza-aminzadeh!
d962cda to
37380e0
Compare
…n (chr-hertel) This PR was merged into the main branch. Discussion ---------- [Platform] Fix broken test after merge and test deprecation | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Docs? | no | Issues | | License | MIT Test failure after #2501 Commits ------- 091603b Fix broken test after merge and test deprecation
Every HTTP-based
ModelClientwraps its injected client withEventSourceHttpClient(needed to decode SSE streaming responses), so theresponse held by
RawHttpResultis always a Symfony HttpClientAsyncResponse, itself wrapping aTraceableResponsewhenever HTTP clientprofiling is enabled, which is the default in a full-stack app's dev
environment. Neither class has a dedicated VarDumper caster, and both keep
their network stream alive until it is explicitly consumed.
dump()'ing ordd()'ing aDeferredResultright afterPlatformInterface::invoke(), before the result is ever read, thereforereflects into that live, not-yet-consumed response instead of a safe
snapshot: closures bound to the response, its HTTP client and its internal
chunk-accounting state all get expanded, and poking at that state from
outside the client's own bookkeeping is exactly what the
AsyncResponse/TraceableResponsepair is not designed to tolerate.This PR adds
__debugInfo()toRawHttpResultso it never exposes the liveresponse in a dump, replacing it with a short, static summary of its type
instead of letting the dumper walk into its internals. It also adds
__debugInfo()toDeferredResultso a dump surfaces the conversion state(
pending,convertedorfailed) at a glance, without ever callinggetResult()itself, so inspecting a pending result cannot trigger aconversion as a side effect.
Tests assert that
__debugInfo()never calls any method on the wrappedresponse, that the
httpStreamproperty stays visible, and thatDeferredResult's reported state matches pending/converted/failed withouttriggering a conversion.
No
CHANGELOG.md/UPGRADE.mdchanges, since this is a bug fix only.