Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constrained string model for item IDs #239

Merged
merged 4 commits into from
Jan 25, 2023

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jan 24, 2023

This PR adds a constrained string type for HumanReadableIdentifiers to be used for item_ids throughout. The exact parameters of these can be discussed, but for now, it restricts characters to alphanumeric with dashes and underscores, a maximum length of 16 and minimum of 6 (now removed - tbd).

Unfortunately this type can only be properly used within a pydantic model at the moment (see linked discussion on pydantic repo in the code), which is hopefully good enough for now. Ideally we'd provide an endpoint that can validate these IDs for uniqueness and format without having to create the whole sample first.

Closes #228

@ml-evs
Copy link
Member Author

ml-evs commented Jan 24, 2023

Pushing the discussion one step further, we should consider reinterpreting unique "ID" to mean that the same ID with dash/underscores/capitalisation is not allowed, e.g.,

jdb_2 should block JDB-2 and JdB_2. Ideally we could encode this at the MongoDB index level (I think you can do case-insensitive indexes quit readily, not sure about - vs _).

@jdbocarsly jdbocarsly enabled auto-merge (squash) January 25, 2023 11:26
@jdbocarsly jdbocarsly merged commit df67aa5 into main Jan 25, 2023
@jdbocarsly jdbocarsly deleted the ml-evs/add_item_id_validation branch January 25, 2023 11:35
@ml-evs ml-evs added this to the v0.2 milestone Jan 25, 2023
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.

Validate URL-safety of user-supplied item_ids
2 participants