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

TypeError: unhashable type: 'CoverallsException' #229

Closed
rodrigc opened this issue Jul 8, 2020 · 6 comments · Fixed by #230
Closed

TypeError: unhashable type: 'CoverallsException' #229

rodrigc opened this issue Jul 8, 2020 · 6 comments · Fixed by #230

Comments

@rodrigc
Copy link
Contributor

rodrigc commented Jul 8, 2020

With the latest coveralls 2.1.0 I am seeing this on Python 3.5:

coveralls debug
Missing .coveralls.yml file. Using only env variables.
Testing coveralls-python...
--- Logging error ---
Traceback (most recent call last):
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 986, in emit
    msg = self.format(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 836, in format
    return fmt.format(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 581, in format
    record.exc_text = self.formatException(record.exc_info)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 531, in formatException
    traceback.print_exception(ei[0], ei[1], tb, None, sio)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/traceback.py", line 100, in print_exception
    type(value), value, tb, limit=limit).format(chain=chain):
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/traceback.py", line 439, in __init__
    _seen.add(exc_value)
TypeError: unhashable type: 'CoverallsException'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/crodrigues/.pyenv/versions/venv-3.5.9/bin/coveralls", line 8, in <module>
    sys.exit(main())
  File "/Users/crodrigues/.pyenv/versions/3.5.9/envs/venv-3.5.9/lib/python3.5/site-packages/coveralls/cli.py", line 70, in main
    coverallz.wear(dry_run=True)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/envs/venv-3.5.9/lib/python3.5/site-packages/coveralls/api.py", line 196, in wear
    json_string = self.create_report()
  File "/Users/crodrigues/.pyenv/versions/3.5.9/envs/venv-3.5.9/lib/python3.5/site-packages/coveralls/api.py", line 245, in create_report
    data = self.create_data()
  File "/Users/crodrigues/.pyenv/versions/3.5.9/envs/venv-3.5.9/lib/python3.5/site-packages/coveralls/api.py", line 300, in create_data
    self._data.update(git_info())
  File "/Users/crodrigues/.pyenv/versions/3.5.9/envs/venv-3.5.9/lib/python3.5/site-packages/coveralls/git.py", line 110, in git_info
    exc_info=ex)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 1297, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 1421, in _log
    self.handle(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 1431, in handle
    self.callHandlers(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 1493, in callHandlers
    hdlr.handle(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 861, in handle
    self.emit(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 992, in emit
    self.handleError(record)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/logging/__init__.py", line 914, in handleError
    traceback.print_exception(t, v, tb, None, sys.stderr)
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/traceback.py", line 100, in print_exception
    type(value), value, tb, limit=limit).format(chain=chain):
  File "/Users/crodrigues/.pyenv/versions/3.5.9/lib/python3.5/traceback.py", line 455, in __init__
    and exc_value.__context__ not in _seen):
TypeError: unhashable type: 'CoverallsException'

The root cause is due to this change in CoverallsException: f597109#diff-6a984f3be7ff0a322c0997145ef8bd2dR3

@rodrigc
Copy link
Contributor Author

rodrigc commented Jul 8, 2020

I can reproduce with this testcase:

import logging

try:
    raise CoverallsException("Some exception")
except:
    logging.exception("Found an exception")

@rodrigc
Copy link
Contributor Author

rodrigc commented Jul 8, 2020

This is breaking CI for https://github.com/twisted/twisted which uses coveralls for Coverage reporting, for example here:

https://travis-ci.com/github/twisted/twisted/jobs/358642598#L2515

@rodrigc
Copy link
Contributor Author

rodrigc commented Jul 8, 2020

@TimoRoth @TheKevJames In f597109#diff-6a984f3be7ff0a322c0997145ef8bd2dR3 , why did you add __eq__ and __ne__ methods to CoverallsException?

To fix the problem that I was seeing, you could add a __hash_ method as well like this:


class CoverallsException(Exception):
    def __hash__(self):
        return hash(str(self))
  
    def __eq__(self, other):
        if isinstance(other, self.__class__):
            return str(self) == str(other)
        return False

    def __ne__(self, other):
        return not self.__eq__(other)



import logging

try:
    raise CoverallsException("Something")
except:
    logging.exception('Got exception')

But I'm not sure if that is the correct approach.

@TimoRoth
Copy link
Contributor

TimoRoth commented Jul 8, 2020

It was added so this works:
https://github.com/coveralls-clients/coveralls-python/blob/master/tests/cli_test.py#L86

Adding hash like suggested should fix it and seems straight forward enough.

@rodrigc
Copy link
Contributor Author

rodrigc commented Jul 8, 2020

@TimoRoth OK, I submitted #230 to add __hash__()

@TheKevJames
Copy link
Owner

Thanks again for the quick fix -- this has been released in coveralls v2.1.1.

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 a pull request may close this issue.

3 participants