autopush-rs icon indicating copy to clipboard operation
autopush-rs copied to clipboard

Improve Uaid usage (consider a different type)

Open data-sync-user opened this issue 1 year ago • 0 comments

UAIDs are represented by Uuid as are channel_ids. This makes a lot sense except UAID’s representation in the db has historically been of the Uuid “simple” format of all lowercase no dashes (the Python Uuid.hex property returns this format).

Whereas channel_id is stored in the default “hyphenated” style, returned by Uuid::to_string() (and Python’s __str__).

This can become a source of subtle bugs: it’s easy to forget which type of Uuid renders which way.

I think we can avoid this by creating a separate Uaid type wrapping Uuid and rendering the “simple” format via its to_string. Despite using “simple” in the db, we have historically rendered the "hyphenated" style of the Uaid to the client. So this new type's ser/deser would still render hyphenated as the Uuid type does.

Alongside this channel_id could have its own type but it would be a type alias of Uuid.

Then we can call to_string on both types in the db code without worrying about which is formatted which way. Serializing them to the client would continue working as is (rendering “hyphenated”).

A prototype: https://github.com/mozilla-services/autopush-rs/compare/b4298eab64a354...feat/uaid-simple

┆Issue is synchronized with this Jira Task

data-sync-user avatar Apr 19 '23 22:04 data-sync-user