Problem with None values with attributes of complex types

Asked by Ales Klimsa on 2012-01-31

When I put None value into some attribute from ladon complex type. And use this attribute later, there isn't None value, but the attribute definition, eg.{'default': None, 'doc': "Customer's ID", 'type': <class 'int'>, 'nullable': True}.

I have this ladon complex type:
class ContactType(LadonType):
    ID = {
          'type' : int,
          'nullable' : True
          }
    Name = {
            'type' : PORTABLE_STRING,
            'nullable' : True
            }

And this test code:

ct = ContactType()
ct.Name = 'NAME'
print(ct.ID, ct.Name)

will print this:
{'doc': 'ID of contact type', 'type': <class 'int'>, 'nullable': True} NAME

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
jsgaarde Edit question
Solved by:
Ales Klimsa
Solved:
2012-02-07
Last query:
2012-02-07
Last reply:
2012-02-07
jsgaarde (jakob-simon-gaarde) said : #1

Hi Ales.

That is actually correct. This will be interpreted as Null by the dispatcher.

Best Regards
Jakob

Ales Klimsa (ales-klimsa) said : #2

Jakob,
please take a look at this example:

I have this ladon complex types: http://pastebin.com/50mgbKGm
There are three classes: Customer, Contact, ContactType

Customer has many Contacts.
Contact is mebmer of one ContactType.

Then I send this SOAP request: http://pastebin.com/zMT7HYAH
Please focus on this line, contactType is empty(NULL): <contactType xsi:nil="true" xsi:type="ns1:ContactType"/>

I log values of ContactType attributes (ID, Name) on the server side and this is result:
INFO:ID:{'doc': 'ID of contact type', 'type': <class 'int'>, 'nullable': True}
INFO:Name:{'doc': 'Name of contact type', 'type': <class 'str'>, 'nullable': True}

I believe that when I put this object back in response, so the dispatcher will interpret these values as NULLs. But I need work with these attributes on the server. Eg. insert new ContactType into database and this is not possible.

Thanks for answer.

jsgaarde (jakob-simon-gaarde) said : #3

Hi Ales.

Ok, I see the problem, I knew about this effect, but thought I would get around to fixing it before anyone noticed :-)

You probably also noticed that the new-style dictionary type definition only is for primitives for now and not for LadonTypes, that fact is related to the effect you are experiencing.

I hope it is ok it wont be fixed till this weekend.

Best Regards
Jakob

Ales Klimsa (ales-klimsa) said : #4

it will be great if you can repair it to the end of this weekend ;)
But, yesterday I discovered another bug. Maybe it is caused by same effect. I will report it later tonight

Thanks a lot

Ales

Ales Klimsa (ales-klimsa) said : #5

I have another problem, but I believe that it is related to this problem.
Take a look at this SOAP request: http://pastebin.com/aw2kDHtd.
This request is for the same complex type which I reported before (http://pastebin.com/50mgbKGm)

Please notice this line: <contacts xsi:nil="true"/>. I left contacts attribute empty.

And I got this error in response:
"Traceback (most recent call last):
File "/python3/lib/python3.2/site-packages/ladon-0.6.7-py3.2.egg/ladon/server/dispatcher.py", line 142, in dispatch_request result = self.call_method(method,req_dict,tc,export_dict)
File "/python3/lib/python3.2/site-packages/ladon-0.6.7-py3.2.egg/ladon/server/dispatcher.py", line 69, in call_method args += [arg['type'](prime_dict=val,tc=tc,export_dict=export_dict)]
File "/python3/lib/python3.2/site-packages/ladon-0.6.7-py3.2.egg/ladon/types/ladontype.py", line 52, in __init__ attr_name) ladon.exceptions.types.ListAttributeMismatch: classname: attribute: contacts Expected list type for attribute "contacts" got "" " } MESSAE: classname: attribute: contacts Expected list type for attribute "contacts" got ""

jsgaarde (jakob-simon-gaarde) said : #6

Hi Ales

I got it - thanks...

Best Regards
Jakob

jsgaarde (jakob-simon-gaarde) said : #7

Hi Ales.

I have converted this answer to two bugs, and marked it solved, ok?

/ Jakob

Ales Klimsa (ales-klimsa) said : #8

no problem

Ales Klimsa (ales-klimsa) said : #10

I will try it on Monday's evening

Thanks a lot

Ales

Ales Klimsa (ales-klimsa) said : #11

Jakob,
thank you very much for these patches. At least one patch works, but I still have one problem (probably with NULL ladon types).
Please take a look at this SOAP request: http://pastebin.com/Ujriz2Cj
This request is for the same complex type which I reported before (http://pastebin.com/50mgbKGm)

Please notice this line: <contactType xsi:nil="true" xsi:type="ns1:ContactType"/>. This is ladon complex type ContactType, which I left empty.

I log values for this contactType attribute and its attributes (ID, Name) on the server:
2012-02-06 22:00:50,212 - ws - INFO - <src.dto.ContactType.ContactType object at 0x7f54f9570f50>
2012-02-06 22:00:50,212 - ws - INFO - {'doc': 'ID of contact type', 'type': <class 'int'>, 'nullable': True}
2012-02-06 22:00:50,212 - ws - INFO - {'doc': 'Name of contact type', 'type': <class 'str'>, 'nullable': True}

As you can see, contact Type isn't None :(

jsgaarde (jakob-simon-gaarde) said : #12

Hi Ales

Please paste bin a small service that can produce this error and a raw SOAP request along with it.

/ Jakob

Ales Klimsa (ales-klimsa) said : #13

Of course, I will do it this evening.

Thanks Ales

Ales Klimsa (ales-klimsa) said : #14

Here is source code of small test service: http://pastebin.com/YQZKNTuf

Here is the SOAP request: http://pastebin.com/79vHfE1U

And this is the contenct of test.log file:

DEBUG:root:<TestLadon.ContactType object at 0x7f54f95893d0>
DEBUG:root:{'doc': 'ID of contact type', 'type': <class 'int'>, 'nullable': True}
DEBUG:root:{'doc': 'Name of contact type', 'type': <class 'str'>, 'nullable': True}

Thank you very much for help

Ales

jsgaarde (jakob-simon-gaarde) said : #15

Hi Ales.

I think you will find that everything works fine if you make "contactType" nullable ;-)

http://paste.ubuntu.com/833293/

/ Jakob

Ales Klimsa (ales-klimsa) said : #16

Jakob,
you,re right. I didn't notice that ladon complex type can be configured with new (dict) way :)
Thanks a lot for help and sorry for bother you

Ales

jsgaarde (jakob-simon-gaarde) said : #17

Hi Ales.

You are not bothering! you are helping out by testing and challenging.

Best Regards
Jakob Simon-Gaarde

Ales Klimsa (ales-klimsa) said : #18

Jakob,
will be these 2 patches part of some new version of ladon? When you release new one

Thanks for answer

Ales

jsgaarde (jakob-simon-gaarde) said : #19

Hi Ales.

0.7.0 was released yesterday.