Skip to content

fix: habit updates losing data due to partial API updates#32

Open
kozy-codes wants to merge 1 commit intodev-mirzabicer:mainfrom
kozy-codes:fix/habit-updates-losing-data
Open

fix: habit updates losing data due to partial API updates#32
kozy-codes wants to merge 1 commit intodev-mirzabicer:mainfrom
kozy-codes:fix/habit-updates-losing-data

Conversation

@kozy-codes
Copy link

Problem

Habit check-ins and updates were disappearing after being recorded. For example, checking into a habit would initially show success, but the check-in would vanish shortly after.

Root Cause

TickTick's habits/batch API requires full object replacement, not partial updates. When only some fields are sent in an update request, the omitted fields are reset to their default values (null/0).

This means:

  • Checking in a habit would reset other fields like name, color, goal, etc.
  • Archiving/unarchiving would lose check-in history
  • Any habit update would potentially corrupt other habit data

Solution

Modified all habit update operations to:

  1. Fetch the complete original habit first
  2. Merge the new values with all original values
  3. Send the complete object back to the API

Changes

src/ticktick_sdk/api/v2/client.py

  • Added missing parameters to update_habit():

    • sort_order
    • target_start_date
    • completed_cycles
    • ex_dates
    • style
    • etag
    • created_time
  • Added new method full_update_habit(habit_data: dict) for sending complete habit dictionaries directly to the batch API

src/ticktick_sdk/unified/api.py

Updated the following methods to fetch original habit and send all fields:

  • update_habit() - Now preserves all original fields when updating specific properties
  • checkin_habit() - Uses full_update_habit() with complete Habit object converted via to_v2_dict()
  • archive_habit() - Sends all fields with status=2
  • unarchive_habit() - Sends all fields with status=0
  • batch_checkin_habits() - Uses full_update_habit() for each habit update

Testing

  1. Check in to a habit
  2. Verify the check-in persists (refresh/re-fetch)
  3. Check in again and verify total increments correctly
  4. Archive and unarchive a habit, verify all data preserved

- TickTick habits/batch API requires full object replacement, not partial updates
- Added missing parameters to update_habit() (sort_order, target_start_date, etc.)
- Added full_update_habit() method for sending complete habit objects
- Updated checkin_habit(), archive_habit(), unarchive_habit() to preserve all fields
- Fixes issue where habit check-ins would disappear after being recorded
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.

1 participant