Skip to content

TypeError exception when calling service operation with a default attribute for parameter of type dateTime  #395

Closed

Description

@joahim

When calling a service operation that has a parameter of type dateTime with the default value set in the WSDL, the following exception is raised in:

https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/xsd/types/builtins.py#L129

TypeError: combine() argument 1 must be datetime.date, not str

The WSDL definition (excerpt):

<s:element name="ItemList">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" default="1899-12-30T00:00:00" name="DateFrom" type="s:dateTime"/>
      <s:element minOccurs="0" maxOccurs="1" default="1899-12-30T00:00:00" name="DateTo" type="s:dateTime"/>
    </s:sequence>
  </s:complexType>
</s:element>

Since the accepted_types = (datetime.datetime,) + six.string_types for DateTime a possible solution would be to simply return the value unchanged if it's of type str in:

https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/xsd/types/builtins.py#L120

class DateTime(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns('dateTime')
    accepted_types = (datetime.datetime,) + six.string_types

    @check_no_collection
    def xmlvalue(self, value):

        if isinstance(value, str):
            return value

        # Bit of a hack, since datetime is a subclass of date we can't just
        # test it with an isinstance(). And actually, we should not really
        # care about the type, as long as it has the required attributes
        if not all(hasattr(value, attr) for attr in ('hour', 'minute', 'second')):
            value = datetime.datetime.combine(value, datetime.time(
                getattr(value, 'hour', 0),
                getattr(value, 'minute', 0),
                getattr(value, 'second', 0)))

        if getattr(value, 'microsecond', 0):
            return isodate.isostrf.strftime(value, '%Y-%m-%dT%H:%M:%S.%f%Z')
        return isodate.isostrf.strftime(value, '%Y-%m-%dT%H:%M:%S%Z')

Activity

  1. changed the title [-]TypeError exception when calling service operation with a default set for parameter of type dateTime [/-] [+]TypeError exception when calling service operation with a default attribute for parameter of type dateTime [/+] on Mar 21, 2017
  2. Vorobeyko commented on Oct 6, 2017

    @Vorobeyko

    Please, fix this defect or say me workaround for this situation?

  3. livexk commented on Oct 25, 2017

    @livexk

    please

  4. added a commit that references this issue on Jan 17, 2018
  5. vikulin commented on Jan 17, 2018

    @vikulin
  6. arturgspb commented on Dec 12, 2018

    @arturgspb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions