An exception was raised processing LadonType attribute

Asked by Ales Klimsa

Hi,
I get this error, when I run WS method:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/python3/lib/python3.2/site-packages/ladon-0.6.5-py3.2.egg/ladon/server/wsgi_application.py", line 358, in __call__
    response_part = dispatcher.dispatch_request(request_data,environ)
  File "/python3/lib/python3.2/site-packages/ladon-0.6.5-py3.2.egg/ladon/server/dispatcher.py", line 161, in dispatch_request
    res_dict = self.result_to_dict(method,result,tc,export_dict['response_attachments'])
  File "/python3/lib/python3.2/site-packages/ladon-0.6.5-py3.2.egg/ladon/server/dispatcher.py", line 124, in result_to_dict
    res_dict['result'] = result.__dict__(tc,response_attachments)
  File "/python3/lib/python3.2/site-packages/ladon-0.6.5-py3.2.egg/ladon/types/ladontype.py", line 200, in __dict__
    attr_name)
ladon.exceptions.types.AttributeConversionException:
classname: <class 'Project365APIWebServices.Customer'>
attribute: LegalForm
An exception was raised
--------------------------------------------------------------------
I have this complex type:
class Customer(LadonType):

    ID = int
    LegalForm = int
    CompanyName = PORTABLE_STRING
    DegreeBefore = PORTABLE_STRING
    FirstName = PORTABLE_STRING
    LastName = PORTABLE_STRING
    DegreeAfter = PORTABLE_STRING
    CompanyID = PORTABLE_STRING
    VAT = PORTABLE_STRING
    BankAccount = PORTABLE_STRING
    InvoiceTogether = PORTABLE_STRING
    Author = PORTABLE_STRING
    CreationIP = PORTABLE_STRING
    CreationDate = PORTABLE_STRING
    ChangedBy = PORTABLE_STRING
    ChangeIP = PORTABLE_STRING
    ChangeDate = PORTABLE_STRING

and this WS method:

@ladonize(PORTABLE_STRING,rtype=Customer)
    def getCustomer(self, name):
        """
        Get information about customer
        """
        db = Customer()
        db.FirstName = "Ales"
        db.ID = 10
        db.LastName = "Klimsa"
        return db

URL to WSDL is here: http://ws.dev.savvy.cz/service/Project365APIWebServices/soap/description

I noticed that the error occur for any other type than PORTABLE_STRING. Could you advice me?

Thank you

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
No assignee Edit question
Solved by:
Ales Klimsa
Solved:
Last query:
Last reply:
Revision history for this message
jsgaarde (jakob-simon-gaarde) said :
#1

Hi Ales.

The reason you are getting that error is because you only initialize 3 of the 17 attributes.
If you want to have default values for your Customer type attributes, you must define them in a Customer __init__ method:

ex:

class Customer(LadonType):
    ID = int
    LegalForm = int
    CompanyName = PORTABLE_STRING
    DegreeBefore = PORTABLE_STRING
    FirstName = PORTABLE_STRING
    LastName = PORTABLE_STRING
    ...

    def __init__(self, **kw): # Note the **kw
        self.ID = -1
        self.LegalForm = -1
        self.CompanyName = PORTABLE_STRING()
        self.DegreeBefore = PORTABLE_STRING()
        self.FirstName = PORTABLE_STRING()
        self.LastName = PORTABLE_STRING()
        ...
        super(Customer, self).__init__(**kw)

NOTE: the last call to LadonTypes __init__() method is a must!

Revision history for this message
Ales Klimsa (ales-klimsa) said :
#2

And what if I need to have some attribute empty (Nulll)? Because I put these values into database and I need store NULL value into columns when the attribute is empty.

And I have another question about datetime data type, it is possible to use it in complex types?

Revision history for this message
jsgaarde (jakob-simon-gaarde) said :
#3

Hi Ales.

Nullable attributes are in the roadmap, and have been it for a long time. So it is actually not a bug you are mentioning here but a missing feature :-)

I can understand that you want this feature, but I must argue that in far the most situations you can implement the needed functionallity using default values like '', -1 etc.

Since I don't have any pending bugs on Ladon, I'd like to start implementing nullable attributes right away. To implement nullable attributes it is nessecary to specify a notation format so the framework can identify when attributes can be nulled.

Suggestions:

1:
class MyType(LadonType):
  username = PORTABLE_STRING
  firstname = PORTABLE_STRING
  lastname = PORTABLE_STRING

  _nullable = ['lastname','firstname']

2:
class MyType(LadonType):
  username = PORTABLE_STRING
  firstname = {type=PORTABLE_STRING, nullable=True}
  lastname = {type=PORTABLE_STRING, nullable=True}

About datetime types. There is no real standard for transporting time objects in SOAP or json. The way I usually transport date or timestamps is by converting them to ISO format with UTC timezone using the datetime method .isoformat(). That way the reciever client can almost certainly parse the timeobject.

It could be argued that Ladon should have some kind of default support for datetime attributes, but it is not in the spirit of Ladon to put constraints of use on the end-service-developer.

You can easally develope helper classes for datetime handling and have your LadonTypes inherit it... example:
http://paste.ubuntu.com/811744/

Best regards
Jakob Simon-Gaarde

Revision history for this message
Ales Klimsa (ales-klimsa) said :
#4

Hi Jakob,
thanks for answer !

I can't agree with using default values (-1, '' etc.), especially integers types. When I use -1 value as NULL value and ws client send me -1 value in some integer attribute, how can I recognize that user wants send me -1 or NULL value?

So it will much helps us , if you implements nullable attributes. I like option 2.
Please give me feedback when the new version of ladon will be ready.

About datetimes types.I completely agree with you. I just asked for this possibilty

Thanks a lot for you time and for doing great job with ladon!

Ales

Revision history for this message
jsgaarde (jakob-simon-gaarde) said :
#5

Hi Ales.

All new versions are announced via facebook, twitter and google+, just toon in on one of those channels and I'm sure you will catch the news ;-)

Best Regards
Jakob Simon-Gaarde

Revision history for this message
jsgaarde (jakob-simon-gaarde) said :
#6

Hi Ales

Can you confirm this solved?

Best Regards
Jakob Simon-Gaarde

Revision history for this message
Ales Klimsa (ales-klimsa) said :
#7

Thanks a lot for new version of ladon. It's work fine ;-)