-
Notifications
You must be signed in to change notification settings - Fork 93
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
Added Support For Apache JSON and Binary Data #139
Conversation
…ng converted properly back from json deserialisation
Codecov Report
@@ Coverage Diff @@
## master #139 +/- ##
==========================================
+ Coverage 83.14% 84.05% +0.91%
==========================================
Files 43 44 +1
Lines 3921 4133 +212
==========================================
+ Hits 3260 3474 +214
+ Misses 661 659 -2
Continue to review full report at Codecov.
|
Some CI has failed, could you please fix it? |
@ethe don't merge yet, I have some problems in my own codebase where |
@ethe feel free to check it out now |
This reverts commit 18dd0fb
Hi @JonnoFTW I approved this PR, thanks! |
@ethe are you happy to merge now? All tests pass along with those in my interoperability repo. |
…ated calls to `self.trans.read(1)` takes a long time with large requests
Merged, thank you for your patience and contribution. |
Added TType.Binary support Relevant to this pull request to add binary support to thriftpy2: Thriftpy/thriftpy2#139
I've been using Thriftpy2 with a private Thrift server for a long time now, and this latest addition has broken things for me. Sorry I can't share the Thrift files, but here's the error when making an RPC call:
|
@dmulter are you able to provide a test case to recreate this? Also did you install from pypi or from git? |
Normally I would provide a test case, but I'm not sure I can in this case. I'm not responsible for the server, it's complex, and under NDA. It uses I install your package from PyPI. I do a pretty standard |
Can you try installing from git? |
Fails the same way. |
@dmulter can you please give a minimum working example or just tell me exactly what combination of client/server protocols and transports you are using on each end. I'll add it to the tests and see if I can recreate the problem. |
@dmulter could you please provide a sample IDL file? we need to reproduce it. |
@dmulter I'm unable to replicate the problem you are having, here's my test case (it still passes if I use Spec:
import time
from thriftpy2 import load
from thriftpy2.transport.memory import TCyMemoryBuffer
from thriftpy2.protocol import cybin
from thriftpy2.thrift import TType
from thriftpy2.rpc import make_client, make_server
from multiprocessing import Process
def test_tcompact_memory_buffer():
spec = load("binary_test.thrift")
factory = cybin.TCyBinaryProtocolFactory()
obj = spec.BinarySpec(
str2bin={"key": b"Binary Value"},
str2str={"key": "String Value"}
)
class Handler:
def run(self, b_spec):
print("\nServer received:")
print(b_spec)
return b_spec
def run_server():
server = make_server(
service=spec.BinaryService,
handler=Handler(),
proto_factory=factory,
)
server.serve()
proc = Process(target=run_server)
try:
proc.start()
time.sleep(0.5)
client = make_client(spec.BinaryService, proto_factory=factory)
res = client.run(obj)
assert res
print("Server sent:")
print(res)
finally:
proc.kill()
time.sleep(0.2) Gives the output:
If you could modify this test so that it fails in the same way your code does, that would be very useful in fixing the issue. |
Some additional status:
xxx.thrift:
test_xxx.py: import time
import sys
from thriftpy2 import load
from thriftpy2.rpc import make_client, make_server
from multiprocessing import Process
class Handler:
def openSession(self, sessionId, clientVersion):
print(f"\nServer received: sessionId={sessionId} clientVersion={clientVersion}")
sys.stdout.flush()
def run_server():
print("Starting server...")
server = make_server(
service=spec.PrivateService,
handler=Handler(),
)
server.serve()
spec = load("xxx.thrift")
def test_private_service():
proc = Process(target=run_server)
try:
proc.start()
time.sleep(0.5)
print("Calling openSession...")
client = make_client(service=spec.PrivateService)
session_id = "xxx"
client.openSession(session_id, spec.kServerApiVersion_Current)
assert False, "tests actually worked" # so we can see print output
finally:
proc.kill()
time.sleep(0.2) |
Installed Cython and built from source. Currently experimenting with what's returned from the server. Not sure if it helps, but the |
Found the problem and it was not this PR, but a different change on 0.4.13. The protocol error was because HTML for an error page was being returned. The breaking change was due to an inserted path separator after port as I'm passing a parsed URL as follows: from urllib.parse import urlparse
url = urlparse(full_url)
client = make_client(
service=spec.TestService,
scheme=url.scheme,
host=url.netloc,
path=url.path,
port="443"
) And the change was faf1055 |
#13 Added support for apache json, so that apache thrift server/clients can talk to thriftpy2 server/clients.
#136 Added support for binary data fields, I'm not sure what ramifications this would have on python2.