Skip to content

fix: make routineId nullable to prevent crash on free workout logs#1257

Open
mmustafasenoglu wants to merge 2 commits into
wger-project:masterfrom
mmustafasenoglu:fix/null-routine-id-crash
Open

fix: make routineId nullable to prevent crash on free workout logs#1257
mmustafasenoglu wants to merge 2 commits into
wger-project:masterfrom
mmustafasenoglu:fix/null-routine-id-crash

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Summary

Makes routineId nullable in WorkoutLogTable and Log model to fix a crash when workout logs have no associated routine.

Problem

The server allows workout logs without a routine (free/ad-hoc logging): routine = ForeignKey('Routine', ..., null=True). However, the app's Drift table declared routineId as non-nullable, causing:

Null check operator used on a null value

in WorkoutLogTableTable.map when PowerSync delivers a row with routine_id = NULL.

Changes

  • WorkoutLogTable.routineId: integer()integer().nullable()
  • Log.routineId: late intint?
  • Log constructor: required this.routineIdthis.routineId
  • Log.toCompanion: handle null routineId with Value.absent()

Testing

Verified that the app no longer crashes when opening a routine that has workout logs without an associated routine.

Fixes #1250

Server allows workout logs without a routine (free/ad-hoc logging),
but the app's Drift table declared routineId as non-nullable.
This caused a null check operator crash when PowerSync delivered
a row with routine_id = NULL.

Changes:
- WorkoutLogTable.routineId: integer() → integer().nullable()
- Log.routineId: late int → int?
- Log constructor: required this.routineId → this.routineId
- Log.toCompanion: handle null routineId with Value.absent()

Fixes wger-project#1250
@rolandgeider

Copy link
Copy Markdown
Member

thanks for the PR @mmustafasenoglu ! it seems you need to commit the changed generated files

@mmustafasenoglu

Copy link
Copy Markdown
Author

Hi @rolandgeider, thanks for the review! The generated files have been committed now — database.g.dart has been regenerated with the nullable routineId changes. The PR should be ready for another look.

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.

Crash "Null check operator used on a null value" in WorkoutLogTableTable.map when a workout log has routine_id = NULL

2 participants