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

Raise error on unknown options #147

Open
fschwahn opened this issue Oct 4, 2022 · 7 comments
Open

Raise error on unknown options #147

fschwahn opened this issue Oct 4, 2022 · 7 comments

Comments

@fschwahn
Copy link

fschwahn commented Oct 4, 2022

We just caught the following during code review:

model.to_sgid(purpose: :api, expires_at: 1.day.from_now.end_of_day)

The correct option to pass is for instead of purpose. This went unnoticed because everything still works, but the default purpose is used.

Maybe it would make sense to raise an error in case an unknown option is passed to to_sgid (and friends)?

@dhh
Copy link
Member

dhh commented Dec 16, 2022

Would be nice to switch this to kwargs. Do investigate a PR.

@fschwahn
Copy link
Author

fschwahn commented Jan 3, 2023

I quickly looked into this, but this change is not possible without changing API. The reason is that all unknown options are converted to params, so for the example above this would yield: gid://app/Model/123?purpose=api.

This could be made explicit by requiring users to pass params explicitly (eg. model.to_sgid(params: { purpose: "api" }, expires_at: 1.day.from_now.end_of_day)), but I'm not sure such a breaking change would be feasible. It'd require a deprecation cycle for sure, but I'm not sure it's worth the effort?

@rafaelfranca
Copy link
Member

Doesn't def to_sgid(expires_at: nil, for: :default, **params) work?

@fschwahn
Copy link
Author

fschwahn commented Jan 4, 2023

Ah sure, switching to kwargs is still possible (and may be worthwhile), but wouldn't fix the problem I originally ran into - namely that someone tried to change the purpose using the wrong keyword (ie. purpose instead of for).

@rafaelfranca
Copy link
Member

oh, right. Yeah, I'm not sure it is worth the effort to have a deprecation cycle.

@fschwahn
Copy link
Author

fschwahn commented Jan 5, 2023

Just to clarify, are you saying "let's do the change, but not have a deprecation cycle" or "let's not do the change"?

@rafaelfranca
Copy link
Member

I'm not sure if doing the change is worth. The new API would be worse for the most common use case. Sure, it means that people will sometimes make mistakes in the call, but that is why we recommend to write tests.

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

No branches or pull requests

3 participants