﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30405	IndexError in _get_lines_from_file when module does not match file contents (via loader)	Daniel Hahler	Hasan Ramezani	"{{{
self = <django.views.debug.ExceptionReporter object at 0x7f2a7908ac18>
filename = '…/project/.venv/lib/python3.7/site-packages/pdb.py'
lineno = 230
context_lines = 7
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7f2a73609278>
module_name = 'pdb'

[23]   …/Vcs/django/django/core/handlers/exception.py(90)response_for_exception()
-> response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
[24]   …/Vcs/django/django/core/handlers/exception.py(125)handle_uncaught_exception()
-> return debug.technical_500_response(request, *exc_info)
[25]   …/Vcs/django/django/views/debug.py(94)technical_500_response()
-> html = reporter.get_traceback_html()
[26]   …/Vcs/django/django/views/debug.py(333)get_traceback_html()
-> c = Context(self.get_traceback_data(), use_l10n=False)
[27]   …/Vcs/django/django/views/debug.py(264)get_traceback_data()
-> frames = self.get_traceback_frames()
[28]   …/Vcs/django/django/views/debug.py(427)get_traceback_frames()
-> filename, lineno, 7, loader, module_name,

 385             try:
 386                 context_line = source[lineno]
 387             except:
 388                 __import__('pdb').set_trace()
 389  ->         post_context = source[lineno + 1:upper_bound]
 390
 391             return lower_bound, pre_context, context_line, post_context
(Pdb++) source
['# this file is needed to hijack pdb without eggs', 'import os.path', ""pdb_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'pdb.py')"", 'with open(pdb_path) as f:', ""    exec(compile(f.read(), pdb_path, 'exec'))""]
}}}

It uses the loader (https://github.com/django/django/blob/47885278c669dd7a13a4c3ff7e58e1cbe88af385/django/views/debug.py#L351), which picks up the `pth`, and then the contents does not match the expected line number.

I think it should maybe always use the given filename?!
"	Bug	closed	Error reporting	2.2	Normal	fixed		Florian Apolloner	Accepted	1	0	0	0	0	0
