Comments (4)
I am pretty sure the problem is that you are mixing builders with already-built descriptors. When you do builder.FromMessage(jmd)
, you get a message builder that references already-built file descriptors for all of its dependencies. And then later, you separately add those same dependencies. The typical issue with this would be a case where you have multiple files with the same name -- the copy that comes from your builder plus the reference to the already-built file. But when a message field refers to other messages in the same file, it can also cause import issues where your file builder incorrectly is trying to import the already-built copy of the file with the same path.
I'm afraid, for what you're doing, you'd need to re-create each message descriptor so that the field's refer to other message builders, not to already-built descriptors.
I'll leave this issue open as a feature request: we could possibly add a new field to BuilderOptions
that allows lenience. The safest case would be, if there are both builders and already-built descriptors referenced for the same element (identified by fully-qualified name), then always use the builder. But I think this could be a bit tricky to implement, and there are other edge cases that wouldn't be clearly handled (such as cases where the transitive graph includes more than one already-built descriptor for the same element but no builders, or cases where the graph includes multiple builders for the same element).
from protoreflect.
Thanks, jhump, yes, that confirms my suspicion.
Anyway, I've moved on and instead of building I simply stripped down un-necessary symbols from the original descriptor messages (not the descriptors themselves, as there they are interfaces and offer no Remove API), and it served my purposes.
Besides your proposed improvement (I agree it can be a bit tricky, but still useful to some extent), do you have better ideas on how to retrieve the minimal transitive enclosure (for a given symbol)? I would expect the usage is not so much limited.
from protoreflect.
I implemented something like that in the buf CLI code:
https://github.com/bufbuild/buf/blob/v1.32.0/private/bufpkg/bufimage/bufimageutil/bufimageutil.go#L177
In particular, your sample code doesn't handle custom options, Any messages, or source code info.
That link above basically just uses descriptor protos, not full-blown descriptors. It creates its own minimal index of elements, just enough to do the trimming (which is hopefully cheaper than wrapping everything in full-blown descriptors, but admittedly not yet benchmarked...).
from protoreflect.
Note that link is for informational purposes only. You might fork that code and adapt it to your needs. It is not usable as is -- if you write a program that tries to import that package, it will panic during initialization. (Everything under github.com/bufbuild/buf/private
is that way -- it's meant to be an "internal" package, but it's not named internal so that we can use it from some of our own stuff outside this repo.)
from protoreflect.
Related Issues (20)
- EnumBuilder panics if it contains EnumValue with explicitly set Number HOT 1
- might not be bug: false duplication report due to use of relative path instead of absolute path HOT 6
- SIGSEGV: panic: runtime error: invalid memory address or nil pointer dereference in v1.15.2 HOT 8
- Protoreflect doesn't fall back to to v1alpha when a gRPC unimplemented response is returned HOT 1
- String escaping in protoprint is wrong HOT 1
- First enum value must be 0 in proto3 [protoprint] HOT 2
- missing `{}` after printing option HOT 5
- Upgrade protocompile to v0.7.0 HOT 3
- go build error HOT 3
- Regression upgrading from v1.14.1 to v1.15.4: extensions are resolved recursively instead of non-recursively HOT 1
- Regression upgrading from v1.14.1 to v1.15.4: absolute paths no longer accepted by parser.ParseFilesButDoNotLink HOT 3
- Regression upgrading from v1.14.1 to v1.15.4: new mustBeSource constraint/check HOT 5
- Stub structure and Methods will relay on protobuf API V2 HOT 15
- Fail to compile proto file HOT 2
- Tests broken with google.golang.org/protobuf v1.33.0
- If there are messages nested in the proto file, the numbers will be recognised as strings HOT 2
- invalid memory address or nil pointer dereference HOT 5
- will return Symbol not found when the proto file has enum definition HOT 1
- Is there a way to UseProtoNames? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protoreflect.