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

Fixing bug with jsonrpc._Method caused by debugger #24

Merged
merged 4 commits into from Dec 7, 2015

Conversation

efokschaner
Copy link
Contributor

Whilst debugging jsonrpclib with PyCharm I observed odd behaviour with jsonrpc._Method due to pycharm using the repr, str and dir methods in order to populate its debug information. These calls would be handled by getattr which would modify the object, corrupting the method name chain. xmlrpclib does not have this issue because it does not make the same optimisation of mutating the existing object but returns a new object when getattr is called (this might actually be a preferable approach to what i am proposing, so consider it as another option).

UPDATE:
After working with the library a bit more i think it would be preferable to revert back to the xmlrpclib approach of not mutating _Method and returning a a new instance each time getattr is called. Because it allows code such as this to work:

foo_proxy = jsonrpclib.Server('http://localhost:80')
remote_bar = foo_proxy.objects.bar
remote_bar.baz()
remote_bar.qux()

If we mutate the _Method then the 'qux()' call would not behave as expected.

Let me know if there are any questions or concerns.

Adding __repr__, __str__ and __dir__ to jsonrpc._Method in order to avoid
issues with PyCharm debugger due to these functions being called and
accessing __getattr__ which mutates the _Method object
@efokschaner
Copy link
Contributor Author

@joshmarshall I noticed you're active in the last few days so wanted to necro this and get your thoughts on this issue.

Is it not worth fixing?

@joshmarshall
Copy link
Owner

Hi @efokschaner -

I think it is worth fixing. It looks like this is still the first implementation -- did you want to open a PR with the immutable _Method() approach?

@efokschaner
Copy link
Contributor Author

@joshmarshall Thanks for the reply, I'll prepare the PR with the recommended fix.

@efokschaner
Copy link
Contributor Author

@joshmarshall I've updated the PR with the __gettattr__ change. I decided to keep the __repr__, __str__ and __dir__ implementations as it still provides a better experience.

@efokschaner
Copy link
Contributor Author

@joshmarshall How does this look?

@joshmarshall
Copy link
Owner

@efokschaner
The change looks good, thanks for making it -- however, I think it needs a test to verify the change you made (that you referenced originally -- the varying behavior based on method lookup). On that note, I've opened a pull request (here) that ties into Travis for automated testing. If you (and anyone else) wants to review that, I can merge into master. You can go ahead and merge that branch in here and update the tests, and it will run in Travis too.

Thoughts?

@efokschaner
Copy link
Contributor Author

@joshmarshall
Thanks, I'll take a look at your PR and then update this one with tests.

@joshmarshall
Copy link
Owner

@efokschaner Alright -- 0.1.4 is released on PyPI and in Travis. Let's make this 0.1.5. :)

@efokschaner
Copy link
Contributor Author

@joshmarshall Test is added, let me know how it looks.

@joshmarshall
Copy link
Owner

@efokschaner Hey -- the test looks good. Sorry, I had a pip install issue with the setup.py + the automated Travis push to PyPI last week, so I had to deal with that. Will merge this fix in as 0.1.7 hopefully this weekend if that works for you.

@efokschaner
Copy link
Contributor Author

@joshmarshall fine by me!

@efokschaner
Copy link
Contributor Author

@joshmarshall You might prefer to merge #43 first.

@efokschaner
Copy link
Contributor Author

@joshmarshall Don't forget this one :)

@efokschaner
Copy link
Contributor Author

@joshmarshall any eta on this merge?

@efokschaner
Copy link
Contributor Author

@joshmarshall Just gonna bump this PR, let me know if you're too busy to deal with the merge.

joshmarshall added a commit that referenced this pull request Dec 7, 2015
Fixing bug with jsonrpc._Method caused by debugger
@joshmarshall joshmarshall merged commit 6b69154 into joshmarshall:master Dec 7, 2015
@joshmarshall
Copy link
Owner

Only took me two years, but it's closed now. Thanks so much for your work and patience!

@efokschaner
Copy link
Contributor Author

@joshmarshall Outstanding, you should see my face right now :D

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.

None yet

2 participants