twilio / twilio-python

A Python module for communicating with the Twilio API and generating TwiML.

Home Page:https://www.twilio.com/docs/libraries/python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fetching taskrouter tasks with ordering and evaluateTaskAttributes returns duplicate resources

topher515 opened this issue · comments

Issue Summary

Fetching taskrouter tasks with twilio-python results in duplicate tasks being returned. This only happens when ordering and evaluate_task_attributes GET parameters are used. It looks to be some sort of paging related bug?

Note that duplicates are not returned when using the Twilio API directly. (See notes below)

Steps to Reproduce

  1. Create taskrouter tasks through any means. (See notes below for details on what our tasks look like)
  2. Open python interactive interpreter
  3. Run commands
> from twilio.rest import Client
> cli = Client(...)
> wrk = cli.taskrouter.workspaces(<workspace_sid>)
>>> len([t for t in wrk.tasks.stream(ordering='DateCreated:desc')])
4
>>> len([t for t in wrk.tasks.stream(ordering='DateCreated:asc')])
4
>>> len([t for t in wrk.tasks.stream(ordering='DateCreated:asc',evaluate_task_attributes='1 == 1')])
4
>>> len([t for t in wrk.tasks.stream(ordering='DateCreated:desc',evaluate_task_attributes='1 == 1')])
10   # Extra tasks are inexplicable duplicated

If we print the sids you can see these are duplicates:

>>> [t.sid for t in wrk.tasks.stream(ordering='DateCreated:asc', evaluate_task_attributes='1 == 1')]
['WT419002c0894080dc648f025958546121', 'WT8db0259c3811989473ca142ab5eacda8', 'WTf2bd78dcea6ccb7e51021c23d826ea7f', 'WT1e821be322f0f64ee749459744c9a9d9']
>>> [t.sid for t in wrk.tasks.stream(ordering='DateCreated:desc', evaluate_task_attributes='1 == 1')]
['WT1e821be322f0f64ee749459744c9a9d9', 'WTf2bd78dcea6ccb7e51021c23d826ea7f', 'WT8db0259c3811989473ca142ab5eacda8', 'WT419002c0894080dc648f025958546121', 'WT1e821be322f0f64ee749459744c9a9d9', 'WTf2bd78dcea6ccb7e51021c23d826ea7f', 'WT8db0259c3811989473ca142ab5eacda8', 'WT1e821be322f0f64ee749459744c9a9d9', 'WTf2bd78dcea6ccb7e51021c23d826ea7f', 'WT1e821be322f0f64ee749459744c9a9d9']

Technical Notes

Our tasks look something like:

{
'account_sid': '...',
 'addons': '{}',
 'age': 18907,
 'assignment_status': 'pending',
 'attributes': {
  "task_lifelong_id": "...",
  "task_init_at": "2023-01-26T15:19:12.719868+00:00",
  "task_type": "reviewCaseInstructions",
  "case": {
    "caseType": "generic",
    "escalationIsUrgent": null,
    "createdAt": "2022-06-08T21:43:48.521252+00:00",
    "companyId": "...",
    "escalatedTeamId": null,
    "name": "Case...",
    "typeId": "...",
    "id": "....",
    "autoCreated": true,
    "outcome": null,
    "object": "case",
    "status": "processing"
  }
},
 'date_created': datetime.datetime(2023, 1, 26, 15, 19, 13, tzinfo=<UTC>),
 'date_updated': datetime.datetime(2023, 1, 26, 19, 9, 24, tzinfo=<UTC>),
 'links': {'reservations': 'https://taskrouter.twilio.com/v1/Workspaces/.../Tasks/.../Reservations',
           'task_queue': 'https://taskrouter.twilio.com/v1/Workspaces/.../TaskQueues/...',
           'workflow': 'https://taskrouter.twilio.com/v1/Workspaces/.../Workflows/...',
           'workspace': 'https://taskrouter.twilio.com/v1/Workspaces/....'},
 'priority': 0,
 'reason': None,
 'sid': '...',
 'task_channel_sid': '...',
 'task_channel_unique_name': 'default',
 'task_queue_entered_date': datetime.datetime(2023, 1, 26, 15, 19, 13, tzinfo=<UTC>),
 'task_queue_friendly_name': 'Default',
 'task_queue_sid': '...',
 'timeout': 1209600,
 'url': 'https://taskrouter.twilio.com/v1/Workspaces/..../Tasks/....',
 'workflow_friendly_name': 'Default Workflow...',
 'workflow_sid': '...',
 'workspace_sid': '...'}

It's worth noting that the same problem does not appear when using the Twilio API directly.

> curl -s -X GET 'https://taskrouter.twilio.com/v1/Workspaces/$WRK/Tasks?ordering=DateCreated:desc&EvaluateTaskAttributes=1+%3D%3D+1' \ 
-u $ACCOUNT:$AUTH | jq '.tasks | length'
4
> curl -s -X GET 'https://taskrouter.twilio.com/v1/Workspaces/$WRK/Tasks?ordering=DateCreated:asc&EvaluateTaskAttributes=1+%3D%3D+1' \ 
-u $ACCOUNT:$AUTH | jq '.tasks | length'
4

Technical details:

  • twilio-python version: 6.62.0
  • python version: 3.9.16

This issue has been added to our internal backlog to be prioritized (DI-2567). Pull requests and +1s on the issue summary will help it move up the backlog.

Hi @topher515, I have verified that this is an issue with the API. It's showing duplicate tasks when I curl https://taskrouter.twilio.com/v1/Workspaces/\{workspace_sid}/Tasks?Ordering=DateCreated%3Adesc&EvaluateTaskAttributes=1+%3D%3D+1

In order to properly debug this issue, please file a support ticket.