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

Catch/handle error from __repr__ #85

Open
blueyed opened this issue May 6, 2019 · 3 comments
Open

Catch/handle error from __repr__ #85

blueyed opened this issue May 6, 2019 · 3 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented May 6, 2019

repr() might trigger database queries in Django, and then e.g. pytest-django
might throw an exception that disallows this.

Therefore when using better-exceptions from a debugger it might crash it there.

I think the call to repr should be protected against this.

.venv/lib/python3.7/site-packages/pdb.py:1325: in _format_extra_exception
    fmt_exc = list(better_formatter.format_exception(etype, evalue, tb))
../../Vcs/better-exceptions/better_exceptions/formatter.py:322: in format_exception
    for line in self._format_exception(value, tb):
../../Vcs/better-exceptions/better_exceptions/formatter.py:311: in _format_exception
    formatted, colored_source = self.format_traceback(exc_traceback)
../../Vcs/better-exceptions/better_exceptions/formatter.py:274: in format_traceback
    formatted, colored = self.format_traceback_frame(tb)
../../Vcs/better-exceptions/better_exceptions/formatter.py:234: in format_traceback_frame
    filename, lineno, function, source, color_source, relevant_values = self.get_traceback_information(tb)
../../Vcs/better-exceptions/better_exceptions/formatter.py:227: in get_traceback_information
    relevant_values = self.get_relevant_values(source, frame, tree)
../../Vcs/better-exceptions/better_exceptions/formatter.py:135: in get_relevant_values
    values.append((text, col, self.format_value(val)))
../../Vcs/better-exceptions/better_exceptions/formatter.py:117: in format_value
    v = repr(v)
../../Vcs/django/django/db/models/query.py:250: in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
../../Vcs/django/django/db/models/query.py:274: in __iter__
    self._fetch_all()
../../Vcs/django/django/db/models/query.py:1242: in _fetch_all
    self._result_cache = list(self._iterable_class(self))
../../Vcs/django/django/db/models/query.py:55: in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
../../Vcs/django/django/db/models/sql/compiler.py:1098: in execute_sql
    cursor = self.connection.cursor()
../../Vcs/django/django/db/backends/base/base.py:260: in cursor
    return self._cursor()
../../Vcs/django/django/db/backends/base/base.py:235: in _cursor
    self.ensure_connection()
E   Failed: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
@Delgan
Copy link
Collaborator

Delgan commented May 6, 2019

Good catch!

I think this is implemented but not yet released.

@Qix-
Copy link
Owner

Qix- commented May 7, 2019

I can do a release sometime today :)

@blueyed
Copy link
Contributor Author

blueyed commented May 7, 2019

Note that pytest's Fail exception is derived from BaseException, so would not be caught there.

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

No branches or pull requests

3 participants