-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
Regression: Python FromString(bytearray()) broken on upb #15911
Comments
@ericsalo do you mind taking a look? |
Bouncing this over to @anandolee who knows way more about this stuff than I do. |
Ouch, I've just been hit by this trying to upgrade our large Python large codebase from an old protobuf version to 5.26.1:
Note that this behaviour is at odds with the documentation, which says:
Some (admittedly very quick and dirty) benchmarks show that having to convert via bytes(bytearray) or memoryview(bytearray) has a significant performance hit for us:
Even so, 5.26.1 is still quite a bit faster than the old version (which works fine with bytearray), so the concern I have is more about the 50+ places in our codebase that will need wrapping with bytes() conversions than the performance overhead. Out of interest, here's some comparison benchmarks for our old protobuf version, which show no overhead for using bytearray vs bytes:
|
@anandolee I submitted a quite small PR that would fix this, do you have time to take a look? 🙏 |
fix is pretty simple, just check if the type is bytearray and get the bytes if it is addresses issue: protocolbuffers#15911 Closes protocolbuffers#16691 COPYBARA_INTEGRATE_REVIEW=protocolbuffers#16691 from jensbjorgensen:main 6249e62 PiperOrigin-RevId: 642623917
fix is pretty simple, just check if the type is bytearray and get the bytes if it is addresses issue: protocolbuffers#15911 Closes protocolbuffers#16691 COPYBARA_INTEGRATE_REVIEW=protocolbuffers#16691 from jensbjorgensen:main 6249e62 PiperOrigin-RevId: 642623917
This fix doesn't seem to be in the new 27.2 release from yesterday, is that to be expected? |
I haven't tested it myself, but looking at the tag it should be in there. Did you build it yourself? |
Ah OK - no I haven't tried it, I just didn't see it mentioned in the release notes and I couldn't see it on the 27.x branch, but I probably just misunderstand the release process. I'll grab 27.2 and give it a go. Thanks! :) |
I take it back @chrismiller I looked at the log and also checked out v27.2 in my working copy and I concur that the change is not present in this tag. git merge-base main v27.2 shows: commit 57a6e8d (tag: v27-dev) So I guess the commit that fixed the issue didn't and won't make it into 27.x at all :-( |
Ah that's unfortunate, thanks for confirming though. Not sure quite how other changes do make it into the 27.x branch, but I guess 28.x won't be all that far away at least. |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
the PR to fix this was merged into version 28 |
What version of protobuf and what language are you using?
Python protobuf 4.25.3
Version: since python backend changed to upb
Language: Python
What operating system (Linux, Windows, ...) and version?
Linux (ubuntu 22.04.3)
What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.10.12
What did you do?
python -c 'from google.protobuf import timestamp_pb2; timestamp_pb2.Timestamp.FromString(bytearray())'
What did you expect to see
The program should run without error.
What did you see instead?
Workarounds
I've copied this in from issue #10774 which was closed and archived. This is still not fixed and is a nasty surprise if your python protobuf package requirement is not pinned to 3.x. Bytearrays are more efficient than bytes to work with so I would expect this usage is very common.
The text was updated successfully, but these errors were encountered: