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

Allow the last callback called to add a callback #1373

Merged
merged 5 commits into from
Nov 10, 2014

Conversation

dobesv
Copy link
Contributor

@dobesv dobesv commented Jul 9, 2014

This fixes a bug in the finished and response callbacks where if the last/only callback adds another callback, the newly added callback won't be called afterwards.

This is because when it tries to add the callback, it is added to a new list instance because the callbacks list is empty at that time; the check for whether the callbacks list was created didn't previously distinguish between an empty list and not a list. However, if it is not the last callback in the list, the callbacks list will not be empty and the new callback will be added to the same list and the newly added callback will be called.

Because the code as written appears to be trying to support callbacks adding callbacks, this push request modifies the code so that a callback may add another callback whether it is the last one or not.

An alternative approach would be to modify the code so that callbacks cannot add new callbacks, which also would be reasonable. But I think it's a bug that the behavior depends currently on whether you are in the last/only callback when you try to add another one.

This fixes a bug in the finished and response callbacks where if the last/only callback adds another callback, the newly added callback won't be called afterwards.

This is because when it tries to add the callback, it is added to a new list instance because the callbacks list is empty at that time; the check for whether the callbacks list was created didn't previously distinguish between an empty list and not a list.  However, if it is not the last callback in the list, the callbacks list will not be empty and the new callback will be added to the same list and the newly added callback *will* be called.

Because the code as written appears to be trying to support callbacks adding callbacks, this push request modifies the code so that a callback may add another callback whether it is the last one or not.

An alternative approach would be to modify the code so that callbacks cannot add new callbacks, which also would be reasonable.  But I think it's a bug that the behavior depends currently on whether you are in the last/only callback when you try to add another one.
@mmerickel
Copy link
Member

I'm not sure I like your chosen fix, however the issue should be corrected. Perhaps with an isinstance check to avoid creating the new list? It'd be nice to see a test which produces the error you're fixing.

@dobesv
Copy link
Contributor Author

dobesv commented Jul 23, 2014

I added a test case that will reproduce the problem for response_callbacks.

I'm not sure what you are mean when you say "Perhaps an isinstance check to avoid creating the new list?" Do you mean it should use if isinstance(self.response_callbacks, list) instead of if self.response_callbacks == () ? I don't think that's really any better or worse, if that's how you want it, it's no problem to change.

@mmerickel
Copy link
Member

foo == () just smells a bit fishy. I was wondering if we could do something closer to just foo is None and have response_callbacks default to None so it's either a list or None.

@dobesv
Copy link
Contributor Author

dobesv commented Jul 30, 2014

Hi, I changed it to use None. I also did a version using a deque instead of a list, it seems suitable for the task. But it's a separate commit so it can easily be rolled back if you don't want it.

mmerickel added a commit that referenced this pull request Nov 10, 2014
Allow the last callback called to add a callback
@mmerickel mmerickel merged commit 4ab8688 into Pylons:master Nov 10, 2014
@mmerickel
Copy link
Member

This looks good to me, thanks for the fixes!

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.

2 participants