Menu

#40 AttributeError: 'str' object has no attribute 'year'

2.0
open
nobody
None
2023-08-14
2023-08-14
No

Hi,

I have an issue where I cannot export xs:date field types.

I am trying to set a xs:date type from a yyyy-mm-dd str:

applicant_info.set_BirthDate("2000-12-31")

Then when I export it to an XML I get this error: AttributeError: 'str' object has no attribute 'year'

The xsd defines BirthDate this way:

<xs:element name="BirthDate" type="xs:date" minOccurs="0" />

The error is present also with other xs:date types in the xsd.

Am I loading the date wrongly?

Here is the full log:

  File "/home/davidcamperos/project/models/models.py
    self.export(
  File "/home/davidcamperos/project/models/models.py
    self._exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Applic
  File "/home/davidcamperos/project/models/models.py
    ApplicantInfo_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='Applic
  File "/home/davidcamperos/project/models/models.py", line 5104, in export
    self._exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='applicantType', pretty_print=pretty_print)
  File "/home/davidcamperos/project/models/models.py", line 5147, in _exportChildren
    outfile.write('<%sBirthDate>%s</%sBirthDate>%s' % (namespaceprefix_ , self.gds_format_date(self.BirthDate, input_name='BirthDate'), namespaceprefix_ , eol_))
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/davidcamperos/project/models/models.py", line 458, in gds_format_date
    input_data.year,
    ^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'year'

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.