-
Notifications
You must be signed in to change notification settings - Fork 32
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
approve: handle usernames not in session #126
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good to me, I like how you handled this.
ocflib/account/submission.py
Outdated
request = get_remove_row_by_user_name(user_name).to_request() | ||
stored_request = get_remove_row_by_user_name(user_name) | ||
if not stored_request: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this return an error so that the caller knows about this? i think it should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0
and 1
or an error string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at this from an interface perspective and ignoring celery and all the other details, i'd expect that if i call a function approve_request(username)
and there's no request to be approved with that username, that it raises an exception of some kind, since it wasn't able to approve any request.
i actually think that raising an exception here is probably the right approach, but i get that it's a bit inconvenient because of the way we do error reporting from the create workers (i assume the point of this branch is to avoid the ocflib error emails?).
turns out we actually already exempt ValueError
s from the reporting "middleware", since they usually indicate caller error: https://github.com/ocf/create/blob/f937a2b88984a2b2ffd282421dbf4e8e429c9a4a/create/tasks.py#L60-L69
maybe we should just raise a ValueError
here? it won't generate an ocflib report, and callers (ocfweb or ircbot or whatever) would be able to catch and handle the exception if they want to. if they don't catch the exception, it would (ideally) trigger a crash in ocfweb/ircbot/etc, which is appropriate since this is sort of a caller error.
(i don't think it will actually trigger an error in ircbot, since i don't think it waits to see the result of the call /shrug)
does that seem reasonable? it's possible that my expectations for how this function should behave are inconsistent with other peoples'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think raising an exception makes more sense, given that is really an error from the point of view of the function or any caller. It seems to me that relying on ValueError
s to just not be reported is counter-intuitive though since I don't think anyone would expect that they are just ignored but all other errors are reported.
Maybe longer-term we should have a custom error type that isn't reported for this kind of thing so that errors can be raised that are expected to be handled by callers instead of sending ocflib reports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was thinking about an exception when I first made this PR but it felt weird that, in order to stop an exception, we raise one somewhere else. After fleshing out the options it does make the most sense though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does feel kinda useless for the time being. The caller is gonna catch a ValueError
as opposed to an AttributeError
. That said, if we do go the custom exception route in the future it will make a lot more sense...
ocflib/account/submission.py
Outdated
create_account.delay(request) | ||
dispatch_event('ocflib.account_approved', request=request.to_dict()) | ||
|
||
@celery_app.task | ||
def reject_request(user_name): | ||
stored_request = get_remove_row_by_user_name(user_name) | ||
if not stored_request: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
d3b0417
to
6c0ee4c
Compare
@chriskuehl @jvperrin fixed and force pushed. the first build failed i think because jenkins builds in tmpfs and supernova |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me besides making the error message a bit more descriptive, because right now I don't think it makes it that clear what is going on.
ocflib/account/submission.py
Outdated
request = get_remove_row_by_user_name(user_name).to_request() | ||
stored_request = get_remove_row_by_user_name(user_name) | ||
if not stored_request: | ||
raise ValueError('User not in session') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say something like "No pending request for user"
or something, I don't think the current message is really descriptive of what the problem actually is (what session?).
ocflib/account/submission.py
Outdated
create_account.delay(request) | ||
dispatch_event('ocflib.account_approved', request=request.to_dict()) | ||
|
||
@celery_app.task | ||
def reject_request(user_name): | ||
stored_request = get_remove_row_by_user_name(user_name) | ||
if not stored_request: | ||
raise ValueError('User not in session') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same here)
both of the added tests will fail prior to this patch. users of the approve_request and reject_request functions should catch a ValueError. fixes #81
6c0ee4c
to
ef495d5
Compare
both of the added tests will fail prior to this patch.
fixes #81