Bug 787519

Summary: Unhandled exception importing CSV, "Could not determine delimiter"
Product: [Retired] Beaker Reporter: Steven Lawrance <stl>
Component: inventoryAssignee: Dan Callaghan <dcallagh>
Status: CLOSED DUPLICATE QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 0.8CC: bpeck, mcsontos, rmancy, stl
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-05 05:32:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Failing CSV file none

Description Steven Lawrance 2012-02-05 22:42:06 UTC
Created attachment 559515 [details]
Failing CSV file

In attempting to create some dummy systems, I:

1. exported systems CSV
2. removed all but one entry, and duplicated that with varying FQDNs
3. attempted to import that

and was greeted with a 500.  Somehow I must have wound up with mixed line endings.  Here's the full traceback:

2012-02-06 08:26:05,844 cherrypy.msg INFO HTTP: Page handler: <bound method CSV.action_import of <bkr.server.CSV_import_export.CSV object at 0x7fd2ee4e3c50>>
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/CherryPy-2.3.0-py2.6.egg/cherrypy/_cphttptools.py", line 121, in _run
    self.main()
  File "/usr/lib/python2.6/site-packages/CherryPy-2.3.0-py2.6.egg/cherrypy/_cphttptools.py", line 264, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in action_import
  File "/usr/lib/python2.6/site-packages/turbogears/controllers.py", line 361, in expose
    *args, **kw)
  File "<generated code>", line 0, in run_with_transaction
  File "/usr/lib/python2.6/site-packages/peak/rules/core.py", line 153, in __call__
    return self.body(*args, **kw)
  File "/usr/lib/python2.6/site-packages/turbogears/database.py", line 458, in sa_rwt
    retval = func(*args, **kw)
  File "<generated code>", line 0, in _expose
  File "/usr/lib/python2.6/site-packages/peak/rules/core.py", line 153, in __call__
    return self.body(*args, **kw)
  File "/usr/lib/python2.6/site-packages/turbogears/controllers.py", line 390, in <lambda>
    fragment, options, args, kw)))
  File "/usr/lib/python2.6/site-packages/turbogears/controllers.py", line 425, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "/usr/lib/python2.6/site-packages/turbogears/errorhandling.py", line 77, in try_call
    return func(self, *args, **kw)
  File "<string>", line 3, in action_import
  File "/usr/lib/python2.6/site-packages/turbogears/identity/conditions.py", line 249, in require
    return fn(self, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/bkr/server/CSV_import_export.py", line 93, in action_import
    dialect = csv.Sniffer().sniff(csv_data.read(1024))
  File "/usr/lib64/python2.6/csv.py", line 180, in sniff
    raise Error, "Could not determine delimiter"
Error: Could not determine delimiter

I can't see anything obviously wrong with the CSV (attached), but this should be caught in any case.

Comment 1 Dan Callaghan 2012-06-05 05:32:12 UTC
I don't think this is caused by mixed line endings (the attached CSV has consistent CRLF line endings). Rather it seems to be a bug related to the insane hackery that csv.Sniffer does to guess the delimiter.

In this particular case, I think it's because there are no quote characters in the file (which would normally make the sniffing logic figure everything out), combined with the fact that we only sniff the first 1024 bytes of the uploaded file, which results in the last row having an inconsistent number of columns, which further confuses the sniffing logic.

Anyway, the solution is the same as for bug 802842 -- turn off CSV sniffing and just require the default dialect. So I'm duping this to bug 802842.

*** This bug has been marked as a duplicate of bug 802842 ***