Modify

Opened 8 years ago

Closed 4 years ago

Last modified 4 years ago

#12813 closed defect (cantfix)

TypeError: unsupported operand type(s) for -: 'unicode' and 'datetime.datetime'

Reported by: sandeep.nadkarni@… Owned by: Jun Omae
Priority: normal Component: TicketImportPlugin
Severity: major Keywords:
Cc: sandeep.nadkarni@… Trac Release: 1.0

Description (last modified by Jun Omae)

Getting unicode and datetime.datetime error while importing from xls/csv

Trac - 1.0.10.
TicketImport Plugin - ticketimportplugin-15601 
python 2.7.5
Centos 7.2
File "/usr/lib/python2.7/site-packages/trac/web/main.py", line 554, in _dispatch_request
File "/usr/lib/python2.7/site-packages/trac/web/main.py", line 247, in dispatch
File "build/bdist.linux-x86_64/egg/talm_importer/importer.py", line 86, in process_request
File "build/bdist.linux-x86_64/egg/talm_importer/importer.py", line 130, in _do_import
File "build/bdist.linux-x86_64/egg/talm_importer/importer.py", line 401, in _process
File "build/bdist.linux-x86_64/egg/talm_importer/processors.py", line 153, in end_process_row
File "build/bdist.linux-x86_64/egg/talm_importer/processors.py", line 122, in _save_ticket
File "/usr/lib/python2.7/site-packages/trac/ticket/model.py", line 306, in save_changes
File "/usr/lib/python2.7/site-packages/trac/ticket/model.py", line 376, in _to_db_types
File "/usr/lib/python2.7/site-packages/trac/util/datefmt.py", line 186, in to_utimestamp 

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by Jun Omae

Component: SELECT A HACKTicketImportPlugin
Description: modified (diff)
Owner: set to Jun Omae
Priority: highnormal
Status: newassigned

time and changetime columns cannot be imported from Excel/CSV file.

Please provide how to reproduce and Excel/CSV file if you don't use time and changetime columns.

comment:2 Changed 8 years ago by Jun Omae

Resolution: cantfix
Status: assignedclosed

comment:3 Changed 7 years ago by anonymous

In file /usr/lib/python2.7/site-packages/trac/ticket/model.py change function _to_db_types to something like

def _to_db_types(self, values):
    values = values.copy()
    for field, value in values.iteritems():
        if field in self.time_fields:
            is_custom_field = field in self.custom_fields
            if is_custom_field and value != '' and type(value) == unicode:
                values[field] = str(int(datetime.datetime.strptime(value, '%m/%d/%Y').strftime("%s"))) + "000000"
        else:
            values[field] = value if value else None
    return values

Change '%m/%d/%Y' to whatever format you use in your csv.

comment:4 Changed 4 years ago by P. Koevesdi

Resolution: cantfix
Status: closedreopened

Same Error, on a custom field named due_date, type time.

Importer settings:

[importer]
csv_default_encoding = utf-8
datetime_format = %Y-%m-%d

local variables: dt u'2018-12-31'

comment:5 Changed 4 years ago by Jun Omae

Resolution: cantfix
Status: reopenedclosed

datetime_format option is for date type in excel format. It is unable to use for time field since Trac 1.2.

This issue is reported with Trac 1.0, not 1.2. Please create new ticket if you want to enhance for the time field since Trac 1.2.

comment:6 Changed 4 years ago by Jun Omae

Don't reopen this ticket.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.