Skip to content
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

Incompatible with CPP protobuf implementation for Python #2646

Closed
junghoahnsc opened this issue Jan 30, 2017 · 15 comments
Closed

Incompatible with CPP protobuf implementation for Python #2646

junghoahnsc opened this issue Jan 30, 2017 · 15 comments
Assignees

Comments

@junghoahnsc
Copy link

Hello,

(
I originally filed this to googleapis/google-cloud-python#2971, but this seems to be an issue in protobuf.

cc: @dhermes, @bjwatson, @geigerj
)

I'm trying to use C++ protobuf implementation for Python since pure Python proto is too slow.
But importing gcloud.bigtable package throws an exception TypeError: Descriptors should not be created directly, but only retrieved from their parent..

Is there any way to fix this problem?

Thanks,

  1. OS type and version
    Tested on ubuntu 14.04 / osx 10.12.

  2. Python version and virtual environment information python --version
    Python 2.7.6

  3. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
    google-cloud 0.22.0 / 0.18.3

  4. Stacktrace if available

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jungho.ahn/pyproto/protobuf/xx/local/lib/python2.7/site-packages/google/cloud/bigtable/__init__.py", line 18, in <module>
    from google.cloud.bigtable.client import Client
  File "/home/jungho.ahn/pyproto/protobuf/xx/local/lib/python2.7/site-packages/google/cloud/bigtable/client.py", line 33, in <module>
    from google.longrunning import operations_grpc
  File "/home/jungho.ahn/pyproto/protobuf/xx/local/lib/python2.7/site-packages/google/longrunning/operations_grpc.py", line 47, in <module>
    options=None),
  File "/home/jungho.ahn/pyproto/protobuf/python/google/protobuf/descriptor.py", line 494, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.
  1. Steps to reproduce
// Install CPP proto implementation.
$ git clone https://github.com/google/protobuf.git
$ cd protobuf
$ ./autogen.sh
$ CXXFLAGS="-fPIC -g -O2" ./configure
$ make -j12
$ export PROTOC=$PWD/src/protoc
$ cd python
$ python setup.py bdist_wheel --cpp_implementation --compile_static_extension
$ pip uninstall protobuf
$ pip install dist/<wheel file name> (e.g., protobuf-3.2.0-cp27-cp27mu-linux_x86_64.whl)

// Enable CPP proto implementation.
$ export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
$ python -c 'from gcloud import bigtable'
  1. Code example
    from gcloud import bigtable
@gfernandessc
Copy link

The same issue happens when using google.cloud.bigtable from google-cloud 0.22 or 0.23.

Can we get some resolution here please?

@dhermes
Copy link

dhermes commented Feb 27, 2017

/cc @lukesneeringer

@TeBoring
Copy link
Contributor

TeBoring commented Feb 27, 2017 via email

@dhermes
Copy link

dhermes commented Feb 27, 2017

@TeBoring The error is from a Python file generated via protoc. We don't have any custom behavior, it's all just vanilla usage of protobuf.

@TeBoring
Copy link
Contributor

TeBoring commented Feb 27, 2017 via email

@dhermes
Copy link

dhermes commented Feb 27, 2017

I am referring to the stack trace in the beginning of this issue:
#2646 (comment)

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Feb 27, 2017

@dhermes The stack trace doesn't reveal any generated protobuf files. Can you provide the .proto file that can reproduce the error?

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Feb 27, 2017

The google/longrunning/operations_grpc.py file in the stack trace might be a generated file of grpc. @haberman mentioned he might know what's going on.

@dhermes
Copy link

dhermes commented Feb 27, 2017

Here is the proto.

For comparison, here is the vanilla protoc generated file and here is the protoc generated file with the gprc plugin. (@lukesneeringer's team generates these so I'm not 100% sure how it's done.)

@lukesneeringer
Copy link

I actually dealt with this issue a couple weeks ago:

  • That error happens in protobuf 3.2.x if there is a descriptor being generated in a filename that does not end with _pb2.
  • google/longrunning/operations_grpc.py is provided by google-cloud-core, if I recall correctly. If it is creating descriptors, we need to rename the module (and then expose it in the old module path).

@lukesneeringer
Copy link

lukesneeringer commented Feb 28, 2017

@xfxyjwf @gfernandessc Can you verify (with pip freeze) that you are using googleapis-common-protos with a version of 1.5.2 or above? I pushed out a fix a couple weeks ago for this issue, but if you are still on 1.5.1, you will not have the fix.

If it is still broken after upgrading to 1.5.2, let me know and I will investigate.

Also tagging the relevant pull request for reference.

@gfernandessc
Copy link

Thanks Luke! I can confirm it works now with 1.5.2. Thank you everyone for digging into this over the past day.

@kpayson64
Copy link

@dhermes
The _grpc.py file linked here
Seems to be out of date. I'm not sure if its already resolved at head, but using the latest version of grpcio-tools generates a valid _grpc.py file (no protobuf descriptors)

@lukesneeringer
Copy link

Yeah. I fixed that in 1.5.2.
You can close this, since one of the original folks who raised it has confirmed that it works in the updated version.

@xfxyjwf xfxyjwf closed this as completed Feb 28, 2017
@xfxyjwf
Copy link
Contributor

xfxyjwf commented Feb 28, 2017

Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants