-
Notifications
You must be signed in to change notification settings - Fork 769
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
2 generated files with same message name makes deserialize response error #1462
Comments
Hi, thanks for the question :) May I ask if you're using Typescript or Common JS, and can you show me how you're importing the client classes? I'm wondering, if you could just use type aliases to get around this issue? e.g.
When you're importing the message classes like here?
|
i am using typescript. So you mean i need to edit the generated files manually? because the problem i am facing is that this is happening on the client generated files, not on my code, it is error when deserializing. I need a solution where i dont need to edit the generated code because i run the generation on every CI/CD to make sure it is updated if there are any proto changes |
Ohh i see.. no i wasn't suggesting you to edit the generated files manually.. I was thinking that if you have 2 different versions of Yeah it definitely doesn't make sense for you having to edit the generated files yourself :) So, if it's an error during deserializing, i guess the generated code has confused the 2 If you can provide some more details on what the generated files look like it might help with understanding of this issue. |
yes it confused the 2 statusresponse classes, when i call the request in the first client it checks the statusresponse class of the second class instead These are the classes generated, i omitted some item because i cannot disclose some of the item, but basically there are some differences:
and the other one is
the main function
|
@rizdaputra Aha i see! Thanks for providing the file content! I'm if you could could also share how "RequestStatusResponse" was imported in the 2 generated services? What's the namespace that was used? And would you be able to specify different namespaces so they can be imported in different ways (to avoid the confusions)? |
i think in the auto generated files it is always generated imports like this
so when calling it is doing You mean i change in the proto so the name will be different? I am searching for a solution because the owner of the proto is not me and it is used in multiple application, changing it would break multiple applications that are not maintained by me. Wondering if there is a way to add prefix or suffix when generating the service/client or is there another solution for this |
Could you share the exact command you used for generating the proto & grpc files? I'll take a look at if that's possible! Thanks! |
i used
|
@rizdaputra Hihi! Thanks for providing the commands you used! And sorry for the delay!! So I've tried creating 2 folders like below (under the echo folder):
With And when i run:
I'm getting 2 files, and one of them would be using That seems like it might work without conflict to me? Is this what you're seeing and would this potentially work for you? Thanks! |
@sampajano thank you for getting back and trying to replicate for me, in my case they are in a different folder. But yes code wise the generated code is correct, but when the code is compiled somehow the function calling is actually conflicting and the only one conflicting is the deserialize process of the response. i have another call that are exactly same and it is not conflicting. But when the same response type name with different structure, the type that is used for deserializing the response is wrong |
@rizdaputra Hi thanks for the response!
I'm wondering what exactly is the symptom and error message you're seeing here? Does this happen inside the grpc-web stack, or when you're trying to consume the response from a successfully returned RPC? One thing you could try is to modify the
When i inspected the generated JS files, both files are exporting this same symbol: goog.exportSymbol('proto.grpc.gateway.testing.EchoResponse', null, global); Which might be a source of confusion after both files are compiled in the same JS budle. |
the error i get i assertion error during the deserialization of the response, when i call the Client A, it uses the Client B Response type to check for assertion. Because the response type is the same name but is actually different format i get assertion error even though the response was correct for Client A so is the only solution editing the proto? So it cannot handle the same name even though it is from a different files? I really want to avoid that cause the proto is used in many places and if i edit it then it would be breaking for all of my other services and the owner is not me too |
Could you provide the exact error messages / stack for it?
Yeah i can understand the problem it might create for you.. But based on what i'm seeing, that basically all protos with the exact goog.exportSymbol('proto.grpc.gateway.testing.EchoResponse', null, global); So i believe this might be inherently conflicting. (And TBH, I think If you provide error log though, it might shine more light on how it might be potentially solved. But for now, I'd say your best bet is to modify the package name of one of the protos :) |
Thank you so much for the help. I'll raise this to my team, seems like that is the best solution for this problem |
So i have different proto files, they have each a request that have same message response name but the value and structure are actually different. This cause problem whenever i declare both then one of them is rendered as that message even though i am calling the other function.
e.g.
ClientA has getStatus with response StatusResponse
ClientB has getStatus with response StatusResponse
but the StatusResponse definition in ClientA and ClientB is different but whenver i call each getStatus both are using the StatusResponse when doing assertion.
The text was updated successfully, but these errors were encountered: