gpodder / mygpo

The gpodder.net webservice
http://gpodder.net/
GNU Affero General Public License v3.0
281 stars 87 forks source link

API: Device Synchronization API - Start / Stop Sync returning HTTP status 500 #128

Open dellagustin opened 6 years ago

dellagustin commented 6 years ago

During my work on PR https://github.com/gpodder/mygpo/pull/122 is was testing the Device Synchronization API - Start / Stop Sync (https://gpoddernet.readthedocs.io/en/latest/api/reference/sync.html#post--api-2-sync-devices-(username).json)

I sent the following request

{
  "synchronize": [
    [
      "my-desktop", "cellphone"
    ]
  ]
}

and it is returning HTTP 500

<html>
    <head>
        <title>500 Internal server error (gpodder.net)</title>
        <link rel="stylesheet" type="text/css" href="/static/css/fail.css" />
    </head>
    <body>
        <div id="c">
            <div id="fail">
                <h1>500 - Internal server error.</h1>
                <p>
                The service is currently overloaded.
                Please try again later or contact us.
                </p>
            </div>
        </div>
        <img id="icon" src="/static/failpodder.png">
    </body>
</html>

as a reference, a previous call to https://gpoddernet.readthedocs.io/en/latest/api/reference/sync.html#get--api-2-sync-devices-(username).json was returning:

{
  "synchronized": [],
  "not-synchronized": [
    "cellphone",
    "my-desktop"
  ]
}

I'm able ot sync this devices on the web ui though.

ByteHamster commented 4 years ago

The cause for this is:

File "mygpo/api/advanced/sync.py", line 35, in main
    update_sync_status(request.user, synclist, stopsync)
  File "mygpo/api/advanced/sync.py", line 80, in update_sync_status
    other = user.get_device_by_uid(other_uid)
  File "venv/lib/python3.8/site-packages/django/utils/functional.py", line 241, in inner
    return func(self._wrapped, *args)
AttributeError: 'User' object has no attribute 'get_device_by_uid'

Replacing user.get_device_by_uid(other_uid) with Client.objects.get(user=user, uid=other_uid) leads to more crashes.

@SiqingYu I do not know much about python. Could you please point me into the right direction to fix this? Synchronizing devices using the API will make AntennaPod's sync feature a lot more useful. Our users are currently pretty confused that they need to log into the website to make sync work.