Skip to content

Fix runtime crashes after struct and DateTime migrations#350

Open
timujinne wants to merge 4 commits intoBeamLabEU:devfrom
timujinne:dev
Open

Fix runtime crashes after struct and DateTime migrations#350
timujinne wants to merge 4 commits intoBeamLabEU:devfrom
timujinne:dev

Conversation

@timujinne
Copy link
Contributor

Summary

  • Fix DateTime.utc_now() microsecond crashes in 19 files after :utc_datetime schema migration
  • Fix register_groups to convert plain maps to Group structs preventing sidebar crashes
  • Fix CastError in live sessions page caused by UUID/integer id mismatch

Changes

DateTime truncation (19 files)

PR #347 changed schema fields from :utc_datetime_usec to :utc_datetime but did not add DateTime.truncate(:second) to DateTime.utc_now() calls in contexts. This caused ArgumentError: :utc_datetime expects microseconds to be empty on any DB write.

Fixed in: settings, billing (invoice/order), shop (products/categories/cart), emails (event/log/templates), referrals, tickets, comments, scheduled jobs, auth (user confirm/anonymize), permissions, role assignments, roles, magic link registration.

Group struct conversion

Registry.handle_call({:register_groups, ...}) inserted plain maps directly into ETS without converting to %Group{} structs. Sidebar templates access group fields with dot syntax (.label, .icon, .collapsible) which crashes on plain maps. Added conversion matching the pattern already used in load_from_config_internal.

Live sessions UUID fix

SimplePresence.track_user stores user.uuid in the user_id field, but preload_users_for_sessions passed these UUIDs to get_users_by_ids which queries by integer u.id column, causing Ecto.Query.CastError. Added get_users_by_uuids/1 and use it for presence user preloading.

Test Plan

  • Pre-commit checks passed (format, credo, dialyzer)
  • Module toggle (enable/disable) works without crashes
  • Live sessions page loads without CastError
  • Compilation clean with --warnings-as-errors

The handle_call for register_groups inserted groups directly into ETS
without converting plain maps to Group structs. This could crash
sidebar templates that access group fields with dot syntax when
parent apps pass plain maps via the public register_groups/1 API.
PR BeamLabEU#347 changed all schema fields from :utc_datetime_usec to
:utc_datetime but did not add DateTime.truncate(:second) to all
DateTime.utc_now() calls in contexts and schemas. This caused
ArgumentError crashes on any DB write operation.

Fixed 19 files across settings, billing, shop, emails, referrals,
tickets, comments, scheduled jobs, auth, permissions, and roles.
…r id

SimplePresence stores user.uuid in user_id field but
preload_users_for_sessions passed these UUIDs to get_users_by_ids
which queries by integer id column, causing Ecto.Query.CastError.

Add get_users_by_uuids/1 and use it for presence user preloading.
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