devopshq / tfs

Microsoft TFS API Python client
https://devopshq.github.io/tfs/
MIT License
110 stars 28 forks source link

Unable print the columns grouped under Microsoft - eg - Microsoft.VSTS.Common.Activity #42

Closed Krishnanparri closed 6 years ago

Krishnanparri commented 6 years ago

Unable print the columns grouped under Microsoft - eg - Microsoft.VSTS.Common.Activity

The Python REPL process has exited Running C:\QA\Automation\QA_Effort\Project\TFS_update.py ('System.Id', 'System.WorkItemType', 'System.Title', 'Microsoft.VSTS.Common.Activity', 'System.AssignedTo', 'Microsoft.VSTS.Scheduling.OriginalEstimate', 'Microsoft.VSTS.Scheduling.RemainingWork', 'System.CreatedDate', 'System.State', 'Microsoft.VSTS.Common.ClosedDate') ('ID', 'Work Item Type', 'Title', 'Activity', 'Assigned To', 'Original Estimate', 'Remaining Work', 'Created Date', 'State', 'Closed Date') 33953,Task,QA : Test Case Creation,Vidya Kulkarni <NYMINT\vkulkarni>,2018-07-05T12:04:08.843Z,Closed Traceback (most recent call last): File "C:\QA\Automation\QA_Effort\Project\TFS_update.py", line 27, in print(workitem[0][Microsoft.VSTS.Common.Activity]) NameError: name 'Microsoft' is not defined

SAnCherepan commented 6 years ago

@Krishnanparri, change the line print(workitem[0][Microsoft.VSTS.Common.Activity]) to: print(workitem[0]['Microsoft.VSTS.Common.Activity'])

and see if that works. In your case dictionary key should be a string (field name), while otherwise python looks for variable named Microsoft, which is most likely not present in your code.

Krishnanparri commented 6 years ago

@SAnCherepan - still it is not working -

Traceback (most recent call last): File "C:\QA\Automation\QA_Effort\Project\TFS_update.py", line 58, in print(workitem[j]['Microsoft.VSTS.Common.Activity']) File "C:\Python3.7\lib\site-packages\tfs\resources.py", line 107, in getitem return self.fields[key] File "C:\Python3.7\lib\site-packages\requests\structures.py", line 52, in getitem return self._store[key.lower()][1] KeyError: 'system.microsoft.vsts.common.activity'

SAnCherepan commented 6 years ago

The line KeyError: 'system.microsoft.vsts.common.activity' means that the field Microsoft.VSTS.Common.Activity is not present in a work item. Either your work item type definition does not contain such field, or the field value in a certain work item is empty (AFAIK, TFS does not return keys for empty fields -> no such key -> exception).

Therefore, the tool tries to find the same field but with the System prefix (and fails, obviously). It is implemented this way so you can use e.g. workitem['Title'] instead of workitem['System.Title'].

What I recommend you to do:

  1. Make sure you use the latest version of this tool (the System prefix was auto-included in any fields in older versions).
  2. Make sure your work items have the Activity field and it is not empty. If you have to support empty values then something like
    
    try:
    a = workitem[j]['Microsoft.VSTS.Common.Activity']
    except:
    print('The wi {id} did not have Activity field, using empty value'.format(id=workitem['ID'])
    a = ''

print (a)


should do the trick.
Let us know if it helps.
Krishnanparri commented 6 years ago

Thank you @SAnCherepan - I also realized yesterday that TFS work item cannot be blank - and that's what was causing this problem - Sorry for the confusion caused and thanks for the guidance provided - it was really helpful.