spyne icon indicating copy to clipboard operation
spyne copied to clipboard

msgpack 1.0.0 error

Open bgermann opened this issue 5 years ago • 12 comments

Running the tests with Python 3.9 gives:

self = <spyne.protocol.msgpack.MessagePackDocument object at 0x7f7bcdf3d940> ctx = MessagePackMethodContext( oob_ctx=None, call_start=1603801847.689902, call_end=None, is_closed=False, app=<sp...t_protocol=<spyne.protocol.msgpack.MessagePackDocument object at 0x7f7bcdf3d670>, pusher_stack=[], frozen=True, ))

def gen_method_request_string(self, ctx):
    """Uses information in context object to return a method_request_string.

    Returns a string in the form of "{namespaces}method name".
    """

    mrs, = ctx.in_body_doc.keys()
    if not six.PY2:
      mrs = mrs.decode('utf8')

E AttributeError: 'str' object has no attribute 'decode'

spyne/protocol/msgpack.py:152: AttributeError

See also https://bugs.debian.org/973211

bgermann avatar Oct 30 '20 09:10 bgermann

I can't reproduce this locally with 2.3.15 code. This is probably due to a patch in debian sid's msgpack package. 21c80ddc ought to fix this nevertheless.

plq avatar Oct 30 '20 11:10 plq

It is caused by the newer msgpack version 1.0.0 in sid. There are no patches involved but that version has some breaking changes. I think you can work around that by following the 1.0.0 update advise.

bgermann avatar Oct 30 '20 16:10 bgermann

Ah, thanks for letting me know about that. The msgpack package in PyPI seems to have changed names as well, that's why Spyne CI did not catch anything.

I'll fix this and release 2.13.16 as soon as possible.

plq avatar Oct 30 '20 20:10 plq

35edacdec5b4c63896eafd37f6648e4484fd9f1e (master) and da03ccef1de503d36c75cacb97cc0673787509a9 (2.13) should fix this

would it be possible to test the latest patches before committing to a release?

plq avatar Oct 30 '20 22:10 plq

sure, I will give it a try. should take ~15min

bgermann avatar Oct 30 '20 22:10 bgermann

TestMessagePackServer.test_roundtrip _______________________________________________________________________________________

self = <spyne.test.transport.test_msgpack.TestMessagePackServer testMethod=test_roundtrip>

    def test_roundtrip(self):
       v = "yaaay!"
       class SomeService(Service):
           @rpc(Unicode, _returns=Unicode)
           def yay(ctx, u):
               return u
    
       app = Application([SomeService], 'tns',
                               in_protocol=MessagePackDocument(),
                               out_protocol=MessagePackDocument())
    
       prot = self.gen_prot(app)
       request = msgpack.packb({'yay': [v]})
       prot.dataReceived(msgpack.packb([1, request]))
       val = prot.transport.value()
       print(repr(val))
       val = msgpack.unpackb(val)
       print(repr(val))
    
>      self.assertEqual(val, [0, msgpack.packb(v)])

spyne/test/transport/test_msgpack.py:61: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/twisted/trial/_synctest.py:434: in assertEqual
    super(_Assertions, self).assertEqual(first, second, msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <spyne.test.transport.test_msgpack.TestMessagePackServer testMethod=test_roundtrip>
msg = "Lists differ: [1, b'\\x92\\xa6Server\\xaeInternal Error'] != [0, b'\\xa6yaaay!']\n\nFirst differing element 0:\n1\n0\n\n- [1, b'\\x92\\xa6Server\\xaeInternal Error']\n+ [0, b'\\xa6yaaay!']"

    def fail(self, msg=None):
        """
        Absolutely fail the test.  Do not pass go, do not collect $200.
    
        @param msg: the message that will be displayed as the reason for the
        failure
        """
>       raise self.failureException(msg)
E       twisted.trial.unittest.FailTest: Lists differ: [1, b'\x92\xa6Server\xaeInternal Error'] != [0, b'\xa6yaaay!']
E       
E       First differing element 0:
E       1
E       0
E       
E       - [1, b'\x92\xa6Server\xaeInternal Error']
E       + [0, b'\xa6yaaay!']

/usr/lib/python3/dist-packages/twisted/trial/_synctest.py:377: FailTest
---------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------
b'\x92\x01\xc4\x17\x92\xa6Server\xaeInternal Error'
[1, b'\x92\xa6Server\xaeInternal Error']
---------------------------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------------------------
DEBUG:spyne.model.complex:Got bases for yay from meta: (<class 'spyne.model.complex.ComplexModel'>,)
DEBUG:spyne.model.complex:Got bases for yayResponse from meta: (<class 'spyne.model.complex.ComplexModel'>,)
INFO:spyne.application:Initializing application {tns}Application...
DEBUG:spyne.interface._base:populating spyne.test.transport.test_msgpack.SomeService types...
DEBUG:spyne.interface._base:  enumerating classes for method 'yay'
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.complex.yay'>" for '{tns}yay'
DEBUG:spyne.interface._base:    adding yay.u = <class 'spyne.model.primitive.string.Unicode'>
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.primitive.string.Unicode'>" for '{http://www.w3.org/2001/XMLSchema}string'
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.complex.yayResponse'>" for '{tns}yayResponse'
DEBUG:spyne.interface._base:    adding yayResponse.yayResult = <class 'spyne.model.primitive.string.Unicode'>
DEBUG:spyne.interface._base:populating 'spyne.test.transport.test_msgpack.SomeService' routes...
DEBUG:spyne.interface._base:  adding method SomeService.yay to match '{tns}yay' tag.
DEBUG:spyne.interface._base:From this point on, you're not supposed to make any changes to the class and method structure of the exposed services.
WARNING:spyne.util.appreg:Overwriting application ('tns', 'Application')(<spyne.application.Application object at 0x7fbe75a4c640>).
DEBUG:spyne.server.twisted.msgpack:7fbe79fbcac0 connection made
CRITICAL:spyne.application.server:yay() missing 1 required positional argument: 'u'
Traceback (most recent call last):
  File "/home/bage/Downloads/spyne/spyne/application.py", line 165, in process_request
    ctx.out_object = self.call_wrapper(ctx)
  File "/home/bage/Downloads/spyne/spyne/application.py", line 234, in call_wrapper
    return ctx.descriptor.service_class.call_wrapper(ctx)
  File "/home/bage/Downloads/spyne/spyne/service.py", line 194, in call_wrapper
    return ctx.function(*args)
TypeError: yay() missing 1 required positional argument: 'u'

bgermann avatar Oct 30 '20 22:10 bgermann

:frowning_face:

Can you refer me to a document that explains how to set up this testing environment? Spyne test suite is as green as it gets.

plq avatar Nov 01 '20 19:11 plq

The error that I posted is from a Debian sid which has all of the spyne package's Build-Dependencies installed. Tests are then run via python3 -m pytest --ignore=spyne/test/interop --ignore=examples

bgermann avatar Nov 01 '20 21:11 bgermann

TestMessagePackServer.test_roundtrip_deferred triggers the same error.

bgermann avatar Nov 01 '20 21:11 bgermann

If you cannot reproduce the issue I suggest to release anyway. The Debian package does not have too many users and most of them do not use msgpack with it, I guess. But they will need the other Python 3 compatibility changes.

bgermann avatar Nov 16 '20 14:11 bgermann

Sorry about the late reply

I did reproduce the bug but it gets weirder. The errors appear only when the test suite is run with

python3 -m pytest --ignore=spyne/test/interop --ignore=examples

and not the official (ie python setup.py test) way. I was not able to spend enough time to figure out why.

I'll nevertheless push a release as soon as I can manage.

plq avatar Nov 19 '20 09:11 plq

Seems I totally forgot to post an update here.

2.13.16 was released on Nov 23rd that contains fixes made so far. I'll finalize this as soon as I have time.

plq avatar Dec 19 '20 11:12 plq