Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7651 closed defect (worksforme)

Unable to create version and set time field (can't send a datetime.datetime)

Reported by: pipern Owned by: osimons
Priority: normal Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12


Unable to create version and set time field, as it expects datetime.datetime but that can't be marshalled. If we send it as a string, we get:

xmlrpclib.Fault: <Fault 1: "'unsupported operand type(s) for -: 'str' and 'datetime.datetime'' while executing 'ticket.version.create()'">

Attachments (0)

Change History (4)

comment:1 Changed 8 years ago by pipern

Examples which fail:

attrs = {"time":datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")}
server.ticket.version.create("3.0", attrs)
attrs = {"time":datetime.datetime.utcnow()}
server.ticket.version.create("3.0", attrs)

comment:2 Changed 8 years ago by osimons

Resolution: worksforme
Status: newclosed

Using what protocol? XML-RPC has native support for marshalling datetime values, but that is not the same type as the default Python datetime type. What you want to use is xmlrpclib.DateTime datatype, that according to docs:

DateTime wrapper for an ISO 8601 string or time tuple or localtime integer value to generate 'dateTime.iso8601' XML-RPC value.

Seeing you are working with Python as client, you want to look at the xmlrpclib standard library documentation.

comment:3 Changed 8 years ago by pipern

Ah, thanks for that.

Indeed, this works perfectly:

   attrs = {"time":xmlrpclib.DateTime(datetime.datetime.utcnow())}
   server.ticket.version.create(version, attrs)

comment:4 Changed 8 years ago by osimons

Now even with a test case for illustration (and verification) - see [8688] :-)

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain osimons.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.