facebook-python-business-sdk icon indicating copy to clipboard operation
facebook-python-business-sdk copied to clipboard

Fix AsyncJob.__nonzero__ job complete check

Open xsleonard opened this issue 8 years ago • 5 comments

Async calls can return with job['async_percent_completion'] == 100 yet still not be complete. The response looking like:

<AsyncJob> {
    "account_id": ".....",
    "async_percent_completion": 100,
    "async_status": "Job Running",
    "id": "6035747473269",
    "is_running": true,
    "report_run_id": "6035747473269",
    "time_ref": 1456266098
}

A subsequent call to .get_result() would fail with:

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v2.5/.../insights
  Params:  {}

  Status:  400
  Response:
    {
      "error": {
        "code": 2601, 
        "is_transient": true, 
        "error_subcode": 1815107, 
        "error_user_msg": "Sorry, the report cannot be loaded successfully. Please check if your job status is completed instead of failed or running before fetching the data.", 
        "error_user_title": "Loading Async Ads Report Failed", 
        "message": "Error accessing adreport job.", 
        "type": "OAuthException", 
        "fbtrace_id": "E/qCS/IDH7v"
      }
    }

The actually completed response looks like:

<AsyncJob> {
    "account_id": "164313463899989",
    "async_percent_completion": 100,
    "async_status": "Job Completed",
    "id": "6035747473269",
    "is_running": true,
    "report_run_id": "6035747473269",
    "time_completed": 1456266101,
    "time_ref": 1456266098
}

This patch also checks for job['async_status'] == 'Job Completed' for that reason. Although the async_percent_completion check is irrelevant in light of this.

xsleonard avatar Feb 23 '16 22:02 xsleonard

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

facebook-github-bot avatar Feb 23 '16 22:02 facebook-github-bot

@rituparnamukherjee can we merge this too?

m-vdb avatar Aug 24 '16 15:08 m-vdb

can we include that in 2.7.2 version? it's pretty critic... cc @daphyFB @JiamingFB

m-vdb avatar Sep 15 '16 22:09 m-vdb

Hi, nonzero is not in 2.7. Do you want to merge back to 2.6, or do you actually want to add those features in 2.7?

daphyFB avatar Sep 16 '16 00:09 daphyFB

I don't see any branch referring to the 2.6 version on this repo (plus it's gonna be pretty quickly deprecated). I will port those changes to 2.7 and add tests then :)

m-vdb avatar Sep 16 '16 01:09 m-vdb