CuSO41108 commented on PR #15934:
URL: https://github.com/apache/dubbo/pull/15934#issuecomment-7003102261

   Thanks @RainYuY — I've rewritten the patch to make the change as narrow as 
possible, and I'd like to get a decision on the policy question, since that is 
what `status:need-discussion` seems to be about.
   
   **What actually changes: exactly one thing.** When a value was stored with 
the object API and is not a `String`, `getAttachment(key)` now returns 
`String.valueOf(value)` instead of `null`. Everything else is preserved:
   
   - the empty-value fallback from the client attachment to the server 
attachment (I kept `StringUtils.isEmpty` here, not `== null`, so that behaviour 
is untouched)
   - client-over-server precedence
   - `getObjectAttachment()` still returns the original `Long` / `Integer` / 
POJO **with its type** — nothing is written twice, nothing is converted at 
store time
   - `RpcContextAttachment#getAttachment()` is **unchanged**: it is the strict 
typed view, `RpcContextTest#testObjectAttachment` asserts its `null` result, 
and that test still passes
   
   There was also a real bug hiding behind the `null`. `getAttachment` falls 
back to the server attachment whenever the client lookup comes back empty, so 
with `client = {id: 42L}` and `server = {id: "server-value"}` the old code 
returned `"server-value"` — a value the caller never set on its own side. It 
now returns `"42"`. There is a test for exactly this case.
   
   **On "I set an Integer and get a String back":** `getAttachment` is the 
pre-3.0 contract and its return type is `String` — it can only ever express 
text. `String.valueOf` is the only option that does not lose it entirely, and 
typed reads remain available through `getObjectAttachment`, which is where new 
code should go. The alternative is the current behaviour, where legacy code 
simply cannot read the value at all.
   
   **Decision needed:** should the legacy accessor keep returning `null` and 
force migration to `getObjectAttachment`, or render the value as described 
above? If you prefer keeping it strict, I'm happy to close this PR and turn the 
`// TODO compatible with previous` into an explicit deprecation instead — I'd 
just rather we settle it than leave it open.
   
   One scope note: the deprecated `getAttachments()` map still drops non-String 
entries (`AttachmentsAdapter.ObjectToStringMap#convert`), and I deliberately 
left that alone — changing it would alter what gets forwarded over the wire. 
Happy to follow up separately if you want the two views fully aligned.
   
   @zrlw as you added `status:need-discussion`, would you mind weighing in on 
which way you want this to go?
   
   The patch changed since the LGTM, so a re-review from @wangchengming666 
would also be appreciated. Tracked in #16594.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

  • Re: [PR] [Bug] Fix RpcContex... CuSO41108 (via GitHub) via notifications

Reply via email to