You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When storing the email templates with the additional language argument, it's possible to get an error when using the EmailTemplate.get_by_label function (without passing the language argument).
It allows e.g. creating a template for multiple languages with the same label. But when reading them without the language argument you'd receive a list and not Sihl_email.Template.t option Lwt.t as it is now.
This is an edge case and could be a wanted exception. Either both (create and get) have to use the language argument or neither of them. (Sorry, I missed adding this test)
I'd suggest keeping the signature and writing a warning to the console, that the function was called without the needed language argument (and returning Lwt.return_none).
@mabiede@joseferben I think since the users can specify their own languages, we can't generally have a fallback language. Maybe we could just return the first one that is found (from a list)?
@joseferben@aronerben IMO, there doesn't need to be a fallback. Either the developer chooses to skip the optional language field or he uses it. If there is only one template for a label specified (e.g. single language) this will be returned.
In case there is more than one template (same label, multiple languages), an Exception or a Log.err and None Lwt.t should be returned.
In case of a fallback, may also add an ORDER BY created_at ASC and LIMIT 1 (without being
able to tell that there are other templates available for the specified key).
@mabiede and I had another discussion. If we want to avoid throwing exceptions (which I think Sihl should avoid, or mark the function with _exn), we see two options with two suboptions:
The API is not changed:
We add the LIMIT 1 if no language is provided (language is optional). This way, we only ever fetch one template
We return the first template found*
The API is changed:
We return a list of templates
We return a result if more (or fewer) than one template is found*
* This implies adding a try with around the Caqti call.
@mabiede@aronerben I like the LIMIT 1 idea if it is documented in the function docs because it does the "right thing" for probably most use cases. What do you think?
@mabiede@aronerben I like the LIMIT 1 idea if it is documented in the function docs because it does the "right thing" for probably most use cases. What do you think?
Activity
joseferben commentedon Apr 26, 2022
@mabiede Could we somehow have a fallback mechanism, maybe a fallback language?
aronerben commentedon May 9, 2022
@mabiede @joseferben I think since the users can specify their own languages, we can't generally have a fallback language. Maybe we could just return the first one that is found (from a list)?
mabiede commentedon May 10, 2022
@joseferben @aronerben IMO, there doesn't need to be a fallback. Either the developer chooses to skip the optional language field or he uses it. If there is only one template for a label specified (e.g. single language) this will be returned.
In case there is more than one template (same label, multiple languages), an Exception or a
Log.errandNone Lwt.tshould be returned.In case of a fallback, may also add an
ORDER BY created_at ASCandLIMIT 1(without beingable to tell that there are other templates available for the specified key).
aronerben commentedon May 10, 2022
@joseferben
@mabiede and I had another discussion. If we want to avoid throwing exceptions (which I think Sihl should avoid, or mark the function with
_exn), we see two options with two suboptions:The API is not changed:
LIMIT 1if no language is provided (language is optional). This way, we only ever fetch one templateThe API is changed:
resultif more (or fewer) than one template is found** This implies adding a
try witharound the Caqti call.joseferben commentedon May 10, 2022
@mabiede @aronerben I like the
LIMIT 1idea if it is documented in the function docs because it does the "right thing" for probably most use cases. What do you think?aronerben commentedon May 10, 2022
I like it.