4969: interdiff sometimes fails with a variable used before assignment

grim
chipx86
chipx86

What version are you running?

4.0.6

What's the URL of the page containing the problem?

https://reviews.imfreedom.org/r/1293/diff/3-4/

What steps will reproduce the problem?

Not sure actually, but the interdiff was created via hg rebase and the diff is attached.

What is the expected output? What do you see instead?

The diff instead of a python error :-D

What operating system are you using? What browser?

Linux, Chrome/Firefox

Please provide any additional information below.

We've seen this across a number of review requests, it's not a huge deal as it's interdiffs, but would be great it if was working properly.

Also since this was from a rebase, I've provided a diff with just the files failing in the interdiff as well as the entire diff between the final revision and the one that was obsoleted.

diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -14,6 +14,12 @@ version 3.0.0 (??/??/????):
 	libpurple:
 		Added:
 		* displaying-emails-clear signal (notification signal)
+		* purple_gdk_pixbuf_make_round
+		* purple_gdk_pixbuf_is_opaque
+		* purple_gdk_pixbuf_from_data
+		* purple_gdk_pixbuf_from_image
+		* purple_gdk_pixbuf_new_from_file
+		* purple_gdk_pixbuf_new_from_file_at_size
 		* PurplePluginInfoFlags (PURPLE_PLUGIN_INFO_FLAGS_INTERNAL and
 		  PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD)
 		* purple_plugin_get_dependent_plugins
@@ -223,7 +229,10 @@ version 3.0.0 (??/??/????):
 		  purple_plugin_pref_set_pref_type
 		* purple_prefs_get_type renamed to purple_prefs_get_pref_type
 		* proto_chat_entry has been renamed to PurpleProtocolChatEntry
+		* PurpleProxyType members are now name spaced under PURPLE_PROXY_TYPE_*
+		* purple_proxy_info_get_host renamed to purple_proxy_info_get_hostname
 		* purple_proxy_info_get_type renamed to purple_proxy_in
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -14,6 +14,12 @@ version 3.0.0 (??/??/????):
 	libpurple:
 		Added:
 		* displaying-emails-clear signal (notification signal)
+		* purple_gdk_pixbuf_make_round
+		* purple_gdk_pixbuf_is_opaque
+		* purple_gdk_pixbuf_from_data
+		* purple_gdk_pixbuf_from_image
+		* purple_gdk_pixbuf_new_from_file
+		* purple_gdk_pixbuf_new_from_file_at_size
 		* PurplePluginInfoFlags (PURPLE_PLUGIN_INFO_FLAGS_INTERNAL and
 		  PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD)
 		* purple_plugin_get_dependent_plugins
@@ -223,7 +229,10 @@ version 3.0.0 (??/??/????):
 		  purple_plugin_pref_set_pref_type
 		* purple_prefs_get_type renamed to purple_prefs_get_pref_type
 		* proto_chat_entry has been renamed to PurpleProtocolChatEntry
+		* PurpleProxyType members are now name spaced under PURPLE_PROXY_TYPE_*
+		* purple_proxy_info_get_host renamed to purple_proxy_info_get_hostname
 		* purple_proxy_info_get_type renamed to purple_proxy_in
david
#1 david

The error:

Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/views.py", line 447, in get
    response = renderer.render_to_response(request)
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/renderers.py", line 57, in render_to_response
    return HttpResponse(self.render_to_string(request))
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/renderers.py", line 72, in render_to_string
    return cache_memoize(
  File "/venv/lib/python3.8/site-packages/djblets/cache/backend.py", line 312, in cache_memoize
    results = list(cache_memoize_iter(key,
  File "/venv/lib/python3.8/site-packages/djblets/cache/backend.py", line 254, in cache_memoize_iter
    items = items_or_callable()
  File "/venv/lib/python3.8/site-packages/djblets/cache/backend.py", line 313, in <lambda>
    lambda: [lookup_callable()],
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/renderers.py", line 74, in <lambda>
    lambda: self.render_to_string_uncached(request),
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/renderers.py", line 87, in render_to_string_uncached
    populate_diff_chunks([self.diff_file], self.highlighting,
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/diffutils.py", line 1251, in populate_diff_chunks
    chunks = list(generator.get_chunks())
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 996, in get_chunks
    for chunk in super(DiffChunkGenerator, self).get_chunks(cache_key):
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 161, in get_chunks
    chunks = cache_memoize(cache_key,
  File "/venv/lib/python3.8/site-packages/djblets/cache/backend.py", line 312, in cache_memoize
    results = list(cache_memoize_iter(key,
  File "/venv/lib/python3.8/site-packages/djblets/cache/backend.py", line 254, in cache_memoize_iter
    items = items_or_callable()
  File "/venv/lib/python3.8/site-packages/djblets/cache/backend.py", line 313, in <lambda>
    lambda: [lookup_callable()],
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 162, in <lambda>
    lambda: list(self.get_chunks_uncached()),
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 1119, in get_chunks_uncached
    for chunk in self.generate_chunks(old=old,
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 305, in generate_chunks
    lines = [
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 306, in <listcomp>
    self._diff_line(tag, meta, *diff_args)
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 533, in _diff_line
    old_markup, new_markup = self._highlight_indentation(
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 600, in _highlight_indentation
    new_markup = self._wrap_indentation_chars(
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 646, in _wrap_indentation_chars
    serialized, remainder = serializer(indentation, norm_indent_len_diff)
  File "/venv/lib/python3.8/site-packages/reviewboard/diffviewer/chunk_generator.py", line 688, in _serialize_indentation
    return s, chars[j + 1:]
UnboundLocalError: local variable 'j' referenced before assignment
chipx86
#2 chipx86

I looked into this a bit when you reported this to me, and... the cause of that UnboundLocalError is easily fixed, but it shouldn't be hitting that code to begin with unless it'd be in a state where j would be assigned. So there's a real bug with that function, but also something leading to that function being called. Kinda weird. Going to require some investigation.

chipx86
#3 chipx86

Fix up for review: https://reviews.reviewboard.org/r/12362/

  • -New
    +PendingReview
  • +Release-4.0.x
  • +Component:DiffViewer
  • +chipx86
chipx86
#4 chipx86

Fixed in 86b164ec28d6178f8ede774911cad664bf891e2c.

  • -PendingReview
    +Fixed