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

approve: handle usernames not in session #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kkuehlz
Copy link
Member

@kkuehlz kkuehlz commented Jul 7, 2018

both of the added tests will fail prior to this patch.

fixes #81

@kkuehlz kkuehlz requested a review from abizer July 7, 2018 22:42
Copy link
Member

@jvperrin jvperrin left a 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.

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
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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 ValueErrors 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'.

Copy link
Member

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 ValueErrors 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?

Copy link
Member Author

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.

Copy link
Member Author

@kkuehlz kkuehlz Jul 8, 2018

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...

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@kkuehlz kkuehlz force-pushed the nonexistent_submission branch 2 times, most recently from d3b0417 to 6c0ee4c Compare July 8, 2018 04:38
@kkuehlz
Copy link
Member Author

kkuehlz commented Jul 8, 2018

@chriskuehl @jvperrin fixed and force pushed.

the first build failed i think because jenkins builds in tmpfs and supernova /tmp was full. Once i cleared it and re-ran the build it passed

Copy link
Member

@jvperrin jvperrin left a 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.

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')
Copy link
Member

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?).

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')
Copy link
Member

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
@kkuehlz kkuehlz force-pushed the nonexistent_submission branch from 6c0ee4c to ef495d5 Compare July 8, 2018 18:04
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.

create throws an uncaught exception when you reject a username that doesn't exist
5 participants