Skip to content

Remove undocumented app metadata from scrobble payloads#105

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-scrobble-payload-metadata
Open

Remove undocumented app metadata from scrobble payloads#105
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-scrobble-payload-metadata

Conversation

Copy link
Copy Markdown

Copilot AI commented May 28, 2026

Scrobble payloads were including app_version and date fields not present in the Trakt API docs. When either is None, the API rejects the request with 400 {"error": "Expected string, received null"}.

Fixes #100

Changes

  • trakt/sync.py: Scrobbler._post() now builds the payload with only progress + media JSON:
    # before
    payload = dict(progress=self.progress, app_version=self.version, date=self.date)
    # after
    payload = dict(progress=self.progress)
  • tests/test_scrobble.py: Added test_scrobbler_payload_excludes_app_metadata — patches api().post to capture the outgoing payload and asserts app_version, app_date, and date are absent.
Original prompt

Create a pull request in repository glensc/python-pytrakt to fix issue #100: scrobble payloads currently include undocumented app metadata that can be null and cause Trakt API 400 responses.

Context:

  • Issue: app_version and app_date are not in Trakt API doc and may raise 400 error
  • Repository issue URL: app_version and app_date are not in Trakt API doc and may raise 400 error #100
  • The issue report notes that Trakt's /scrobble/start payload documentation only includes the media object and progress, and that sending app_version: null can trigger 400 {"error": "Expected string, received null"}.

Relevant code identified:

  • trakt/sync.py: Scrobbler._post() currently builds payloads with progress, app_version, and date before adding the media JSON.
  • trakt/movies.py and trakt/tv.py: public scrobble() methods pass app_version and app_date into Scrobbler; changing these call signatures is optional unless needed for compatibility. Keep scope minimal.
  • checkin_media() also uses app_version and app_date, but issue app_version and app_date are not in Trakt API doc and may raise 400 error #100 is specifically about scrobble payloads; do not change checkin behavior unless strictly necessary.
  • Existing scrobble tests are in tests/test_scrobble.py. Mock payload data also exists in tests/mock_data/scrobble.json.

Requirements:

  1. Implement the smallest safe fix so scrobble requests no longer send undocumented app_version / app_date metadata that may be null.
  2. Preserve backward compatibility of the public API as much as possible; avoid unnecessary signature changes if the fix can be isolated to request payload generation.
  3. Add or update tests to prevent regressions and ensure scrobble payloads do not include those fields.
  4. Keep commits atomic and as small as possible.
  5. Follow commit message guidance from https://chris.beams.io/git-commit — concise imperative subject, focused per commit.

Expected likely approach:

  • Update Scrobbler._post() in trakt/sync.py so the payload contains only progress plus media.to_json_singular() content.
  • Add/update tests in tests/test_scrobble.py (and any fixture/mock data if needed) to verify the scrobble payload shape and absence of app_version, app_date, or stray date fields.

Deliverable:

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Propose fix for @glensc/python-pytrakt/issues/100 issue.

When making commits, make the commits atomic, smallest as possible following guidance from https://chris.beams.io/git-commit

Assistant: Proposed fix: stop sending undocumented app_version / app_date fields in scrobble payloads, and add a regression test that would fail if those fields reappear.

Why this is the right fix

  • The current scrobble payload is built in Scrobbler._post() and includes app_version plus date unconditionally. That does not match the issue report or the documented Trakt scrobble payload shape.
  • checkin still appears intentionally built around app_version / app_date, so I would not change checkin as part of issue app_version and app_date are not in Trakt API doc and may raise 400 error #100 unless you want to broaden scope.
  • This keeps the change small and atomic.

Minimal code change

In trakt/sync.py, change Scrobbler._post() from building:

payload = dict(progress=self.progress, app_version=self.version,
               date=self.date)
payload.update(self.media.to_json_singular())
response = yield uri, payload

to:

payload = dict(progress=self.progress)
payload.update(self.media.to_json_singular())
response = yield uri, payload

Regression test to add

Add a test in tests/test_scrobble.py asserting the generated payload does not contain those fields:

# -*- coding: utf-8 -*-
from trakt.movies import Movie
from trakt.sync import Scrobbler


def test_scrobble():
    """test the Scrobbler class's workflow"""
    guardians = Movie('Guardians of the Galaxy', year=2014)
    scrobbler = Scrobbler(guardians, 1.0, '1.0.0', '2015-02-01')
    scrobbler.start()
    scrobbler.update(50.0)
    scrobbler.pause()
    scrobbler.start()
    scrobbler.stop()
    scrobbler.start()
    scrobbler.finish()


def test_scrobbler_context_manager():
    """test the Scrobbler when used as a context manager"""
    guardians = Movie('Guardians of the Galaxy', year=2014)
    with Scrobbler(guardians, 0.0, '1.0.0', '2015-02-01') as scrob:
        for i in range(10):
            scrob.update(i*10)


def test_scrobbler_payload_excludes_app_metadata():
    """scrobble payload should not send undocumented app metadata"""
    guardians = Movie('Guardi...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Fix scrobble payload to remove undocumented app metadata Remove undocumented app metadata from scrobble payloads May 28, 2026
Copilot finished work on behalf of glensc May 28, 2026 14:45
Copilot AI requested a review from glensc May 28, 2026 14:45
@glensc glensc force-pushed the copilot/fix-scrobble-payload-metadata branch from 433c207 to ad1d856 Compare May 28, 2026 14:55
@glensc glensc marked this pull request as ready for review May 28, 2026 14:55
The Trakt scrobble API only requires progress and the media object.
Sending undocumented app_version/app_date fields with null values
causes 400 responses from the API.

Fixes #100

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Verify that scrobble payloads do not include undocumented app_version,
app_date, or date fields that can cause 400 responses from the Trakt API.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@glensc glensc force-pushed the copilot/fix-scrobble-payload-metadata branch from 7492add to beef1b0 Compare May 28, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

app_version and app_date are not in Trakt API doc and may raise 400 error

2 participants