English 中文(简体)
页: 1 实地失踪
原标题:Python - azure-devops - AssignedTo field is missing

我写了一篇论文,摘述了ADO query的成果。

def get_query_results(connection, project_name,query_id):

      
   Gets the result of a query in ADO
      
   results = []
   try:
      wit_client = connection.clients.get_work_item_tracking_client()
      result = wit_client.query_by_id(query_id)

      work_items = result.work_items

      for work_item in work_items:
         work_item_details = wit_client.get_work_item(id=work_item.id, fields=["System.Id", "System.Title","System.AssignedTo"], expand="Relations,Fields")
         results.append({"id": work_item_details.fields[ System.Id ], "title": work_item_details.fields[ System.Title ], "assigned_to": work_item_details.fields[ System.AssignedTo ]})
   except Exception as e:
        logger.exception(f Error fetching repositories from {project_name}: {str(e)} )

   return results

但是,尽管在指定机构内有许多可用的领域,例如“签署协议”,但似乎我不能获得<>签署<>的>协议>。

results.append({"id": work_item_details.fields[ System.Id ], "title": work_item_details.fields[ System.Title ], "assigned_to": work_item_details.fields[ System.AssignedTo ]})
KeyError:  System.AssignedTo 
  • how can I fix this ?
  • how can I retrieve the available fields instead of just guessing ?

感谢您的帮助

问题回答

在使用“wit_client.get_work_item”的功能时,如果该工作项目没有分配给任何用户,则该功能的产出将不包含<>>System.Assign。 在这种情况下,“work_item_details.fields[] 系统<>/代码>将退回错误信息“KeyError: System.AssignTo

为避免这一错误,你可以尝试使用如下功能。

work_item = wit_clinet.get_work_item(xxx)
work_item_assigned_to = work_item.fields.get( System.AssignedTo )
  • If the work item has been assigned to a user, it will return the content of System.AssignedTo .
  • If the work item is not assigned to any user, it will return None instead of an error.




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...