CSV Python Import - Gives exception

I try to import my old bug database to a test-instance of YouTrack in the Cloud.
I now have a complete CSV file and created a mapping for the python importer as I assume it is correct. However, even for my very simple test case I always get an error on the console:

I execute the script like this:
python python/csv2youtrack.py test.csv http://mytest.myjetbrains.com/youtrack myName myPassword

and I get:

Traceback (most recent call last):
  File "python/csv2youtrack.py", line 140, in <module>
    main()
  File "python/csv2youtrack.py", line 20, in main
    csv2youtrack(source_file, target_url, target_login, target_password)
  File "python/csv2youtrack.py", line 35, in csv2youtrack
    importer.import_csv()
  File "python/csv2youtrack.py", line 44, in import_csv
    projects = self._get_projects()
  File "python/csv2youtrack.py", line 93, in _get_projects
    project_id, project_name = self._import_config.get_project(issue)
  File "python/csv2youtrack.py", line 124, in get_project
    project_name = issue[project_name_key]
KeyError: 'Project'


My CSV file is attached. My mapping looks like this:

import csvClient

csvClient.FIELD_NAMES = {
"Project"       :   "project_name",
    "Project Id"    :   "project_id",
    "Summary"       :   "title",
    "Reporter"      :   "createdBy",
    "Created"       :   "createdDate",
    "Description"   :   "bugDescription",
    "Comment"   :   "comment",
    "Issue Id"      :   "id"
}
csvClient.FIELD_TYPES = {
    "Fix versions"      :   "version[*]",
    "State"             :   "state[1]",
    "Assignee"          :   "user[1]",
    "Affected versions" :   "version[*]",
    "Fixed in build"    :   "build[1]",
    "Priority"          :   "enum[1]",
    "Subsystem"         :   "ownedField[1]",
    "OS" :   "enum[1]",
}


csvClient.CSV_DELIMITER = ","
csvClient.DATE_FORMAT_STRING = " %d.%m.%Y %H:%M:%S"



Also I feel the need to express my frustration about the lack of documentation for the python library. There is not the slightest hint in the library how to use the mapping file and what its values mean. I still have no clue why I define the FIELD_TYPES here. Is this to create new fields if they do not exist, or do I need to redeclare any field as it exists in YouTrack?
Will the Python importer also create any missing Users, Projects and Subsystems?
4 comments
Comment actions Permalink
Hi Gabriel,
Does your csv file contain column Project?
0
Comment actions Permalink
No, the according column is called project_name in my CSV. I mapped that to Project in the mapping file (if it is correct how I did it)
0
Comment actions Permalink
Unfortunately, it is not correct. Let me explain how to write right mapping file.
Please, take a look at section FIELD_NAMES. It describes how to map columns from csv file to youtrack fields.
In the example below you can see that column 'Project' is mapped to field 'project_name', column 'Project Id' to field 'project_id', 'Issue Id' to 'numberInProject' and so on...
csvClient.FIELD_NAMES = { 
    "Project"       :   "project_name",
    "Project Id"    :   "project_id",
    "Summary"       :   "summary",
    "Reporter"      :   "reporterName",
    "Created"       :   "created",
    "Updated"       :   "updated",
    "Description"   :   "description",
    "Issue Id"      :   "numberInProject"
}
prettyPrint();
So, if you have column 'MyColumn' in your csv and you want it to be called 'MyField' in youtrack then you should write:
"MyColumn" : "MyField".

Section FIELD_TYPES describes what type to use for certain field.
In the example below you can see that field 'Fix versions' should be of type 'version[*]', field 'State' should be of type 'state[1]' and so on...
csvClient.FIELD_TYPES = { 
    "Fix versions"      :   "version[*]",
    "State"             :   "state[1]",
    "Assignee"          :   "user[1]",
    "Affected versions" :   "version[*]",
    "Fixed in build"    :   "build[1]",
    "Priority"          :   "enum[1]",
    "Subsystem"         :   "ownedField[1]",
    "Browser"           :   "enum[1]",
    "OS" :   "enum[1]",
    "Verified in build" :   "build[1]",
    "Verified by"       :   "user[1]",
    "Affected builds"   :   "build[*]",
    "Fixed in builds"   :   "build[*]",
    "Reviewed by"       :   "user[1]",
    "Story points"      :   "integer",
    "Value"             :   "integer",
    "Marketing value"   :   "integer"
}
prettyPrint();
0
Comment actions Permalink
Thank you very much. That is exactly the information I needed.
0

Please sign in to leave a comment.