Python SDK Datetimes Bug

Hello

I think I have discovered a little bug with the Datetimes and the Python SDK.

I saw it when I was trying to update a queue's name. So, I tried this:

# ...Auth stuff...

routing_api = pc2.RoutingApi()
try:
    # Get the queue
    queue_name = 'my_test_queue'
    api_response: pc2.QueueEntityListing = routing_api.get_routing_queues(name=queue_name)
    retrieved_queue = api_response.entities[0]
    
    # Modify the queue
    retrieved_queue.name = 'my_new_test_queue'
    api_response = routing_api.put_routing_queue(queue_id=retrieved_queue.id, body=retrieved_queue)

except IndexError:
    print('No queues!')
except ApiException as e:
    print('Api error!')
    raise

However, it gave me this error: {"message":"Dates must be specified as ISO-8601 strings. For example: yyyy-MM-ddTHH:mm:ss.SSSZ","code":"invalid.date","status":400}

First, I thought this was because put_routing_queue expects a QueueRequest object, and I was putting a Queue object (although it should work anyway, as they share the same attributes structure). So, I built a QueueRequest from scrach:

# ...Auth stuff...

routing_api = pc2.RoutingApi()
try:
    # Get the queue
    queue_name = 'my_test_queue'
    api_response: pc2.QueueEntityListing = routing_api.get_routing_queues(name=queue_name)
    retrieved_queue = api_response.entities[0]

    # Build the QueueRequest object
    queue_request = pc2.QueueRequest()
    queue_request.name = 'my_new_test_queue'
    queue_request.division = retrieved_queue.division
    queue_request.description = retrieved_queue.description
    queue_request.date_created = retrieved_queue.date_created
    queue_request.date_modified = retrieved_queue.date_modified
    queue_request.modified_by = retrieved_queue.modified_by
    queue_request.created_by = retrieved_queue.created_by
    queue_request.member_count = retrieved_queue.member_count
    queue_request.media_settings = retrieved_queue.media_settings
    queue_request.routing_rules = retrieved_queue.routing_rules
    queue_request.bullseye = retrieved_queue.bullseye
    queue_request.acw_settings = retrieved_queue.acw_settings
    queue_request.skill_evaluation_method = retrieved_queue.skill_evaluation_method
    queue_request.queue_flow = retrieved_queue.queue_flow
    queue_request.whisper_prompt = retrieved_queue.whisper_prompt
    queue_request.auto_answer_only = retrieved_queue.auto_answer_only
    queue_request.enable_transcription = retrieved_queue.enable_transcription
    queue_request.enable_manual_assignment = retrieved_queue.enable_manual_assignment
    queue_request.calling_party_name = retrieved_queue.calling_party_name
    queue_request.default_scripts = retrieved_queue.default_scripts
    queue_request.outbound_messaging_addresses = retrieved_queue.outbound_messaging_addresses
    queue_request.outbound_email_address = retrieved_queue.outbound_email_address
    queue_request.self_uri = retrieved_queue.self_uri

    api_response = routing_api.put_routing_queue(queue_id=retrieved_queue.id, body=queue_request)

except IndexError:
    print('No queues!')
except ApiException as e:
    print('Api error!')
    raise

However, the same error happens again. After some testing, I discovered that if I didn't send the date_created and the date_modified attributes, it would work well. However, that sets those dates to null, which I want to avoid.

So, I think the problem is that somehow the datetime attributes that the get_routing_queues method provides are not accepted by the put_routing_queue method.

Hi Adrian,

Thanks for the submission. We will take a look at it. I suspect what is happening is what we have seen with our other dynamic language SDKs. If you don't populate the parameter, it does not get sent down to the service and if it is not required then they will not complain about it. However, if you set a value to null, the serializer for the SDK will dutifully send along a string called null.

Thanks again for the post and we will take a look.

  • John

Hello John

The problem is that I've seen no way to update a Queue using the SDK without overriding the creation and modification dates. If I set the same ones the retrieved Queue object had, it returns error. If I don't, it sets them to null.

After doing some debugging, I think this could be because of how datetime objects are serialized for the request. In the api_client module of the SDK, there is this code:

elif isinstance(obj, (datetime, date)):
    return obj.isoformat()

This method returns a datetime string like this one: 2020-10-23T12:16:47.843000+00:00, and causes the error. Instead of the +00:00 it should put a 'Z'.

KO:

OK:

Hi Adrian,

So I dug into this further. There are a couple of problems that we need to sort out in the API:

  1. The createdBy, updatedBy, dateModified, dateCreated fields should never be modified directly. Personally, I would like to see them completely ignored, but I need to dig into our Swagger Defs and Swagger SDK generation process and see if we can tell the process to ignore them on the input object.
  2. In the meantime I would just do what you do in the second example where you manually set the properties you want in a new object instance. Make sure you create a QueueRequest object and then copy over all the fields over. (e.g. the media setting values, etc...)
updateQueue = PureCloudPlatformClientV2.QueueRequest()
updateQueue.id=retrieved_queue.id
updateQueue.name='Chat2'

.... Copy all of the rest of the fields

This might take a little time to fix because unfortunately, the long-term solution might span a couple of teams.

Thanks for your feedback on this and we will look further into this.

  • John Carnell
    Manager, Developer Engagement

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.