Skip to content

Commit

Permalink
[v2-10-test] Sort "opts" element in click option dictionary before ha…
Browse files Browse the repository at this point in the history
…shing (apache#45156)

Some impleemntation details of click 8.1.8 caused instability in
configuration directories that are produced by click config - the
instability is in sequence of generated "opts" list - the sequence
of options in it is random.

While it can be likely fixed in later versions, better is to
protect from it and sort the opts list before hashing the dict.
(cherry picked from commit 1796c40)

Co-authored-by: Jarek Potiuk <[email protected]>
  • Loading branch information
potiuk committed Dec 22, 2024
1 parent 721ff80 commit 2a58ada
Show file tree
Hide file tree
Showing 29 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_build-docs.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91166ce4114ea9c162c139d2aff15886
16278718c7278a46f343ae5a64a9ae21
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_ci_fix-ownership.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3e5a73533cc96045e72cb258783cfc96
9decf6bb3eecbe566006f39f22cb331a
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_ci_free-space.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
49af17b032039c05c41a7a8283f365cc
21f9955c2f47b4524f1df73af8594d54
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_ci_resource-check.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bfcca92f18a403ca630955074eb5e9ad
858a3c3a7f47ab6b47364a9fff1c19ac
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_cleanup.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
231de69d5f47ba29c883164e4575e310
45d1ac665d85bff99d1ea396be00f892
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_compile-www-assets.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2c65b08cbff1b5be5b5c55fcd18580a9
5b57c7464757837e78ed9ad7e2b39d6b
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_down.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65834d56aa23a727a3b5a5c6f8197400
17e350cf4ddd966bc9aa142d5452317c
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_exec.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42bbd3c1659128b0341ae118c3482da2
300c15ecdfffbb85926ab31fc775521a
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_generate-migration-file.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
747d68bcaed5decfa6da146eb9c74e64
fe2f7beb040bd87d2ba9ec143c067711
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_k8s_setup-env.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a34e94744ca4e0592371fe55478c3d54
519e87a2048c3f841196e43a09f183f6
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16862ea6a616ef66a192424838062813
085dfd3570b78ad1be8dd95f480be582
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a3834afc4aa5d1e98002c9e9e7a9931d
5b63e90b9597e5a47cc4fbfa32ab9fbe
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15723131610a3be9a3093f346e72ed06
00382e6b2a84a1edbf77eb5ed0a9df72
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3e0e080fa8422853ed7df3967725b35f
798f6631dad1b650e8a48fa5d51d73e6
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d1eb314d4c9e949306d06f079a1463e5
fe93d72f5d749f318b0a13294ea95d08
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8c3be9f78286641f5657f890745ef936
27169c83fcbcca907a0b32a5c4faeb48
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d57dc8d296addbea3fd3285e2063c102
15c3eb3be97998320dc95431840d8b3a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aa5da16329704d537cf3c6d6f38ab8d9
2a24df4fb60b12ac81b2fcbe151c1f8d
Original file line number Diff line number Diff line change
@@ -1 +1 @@
419f48f6a4ff4457cb9de7ff496aebbe
495a5e3d024bc6039290d9f4528a3ca4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7c32e47c0359fa185ab30ed5fc4c91cf
403dae670f839e37c83baa15ac65af9a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
02ec4b119150e3fdbac52026e94820ef
cd4df9af29227f6de406050fbb12dd3b
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fbf15f8f21cdda9f815a801d9e266b61
24b1be5f59a0d7db2bac65edbdb693a1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116a44d6ee103f8b57ce56a3e774c70b
60ea5de9051747f494fe1d40310fba85
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ea2ff499fd3c25ef89abaab313d5d04a
ba00ab3fb2ed5a777684878c28b3ce65
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup_autocomplete.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ec3b4541a478afe5cb86a6f1c48f50f5
3da8dc88411f34d3ed52c155df744c22
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup_self-upgrade.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4af905a147fcd6670a0e33d3d369a94b
9ad9de5cc99ce2133e14d7dc15c1042a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
252c8ee48ca57e6539064544cbd63e58
85797323723a480a895251c1b6db9356
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
be116d90a21c2afe01087f7609774e1e
b41f292ef2af6d7988bedc6effd73263
30 changes: 28 additions & 2 deletions dev/breeze/src/airflow_breeze/commands/setup_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,36 @@ def dedent_help(dictionary: dict[str, Any]) -> None:
dictionary[key] = textwrap.dedent(value)


def dict_hash(dictionary: dict[str, Any], dedent_help_strings: bool = True) -> str:
"""MD5 hash of a dictionary. Sorted and dumped via json to account for random sequence)"""
def recursively_sort_opts(object: dict[str, Any] | list[Any]) -> None:
if isinstance(object, dict):
for key in object:
if key == "opts" and isinstance(object[key], list):
object[key] = sorted(object[key])
elif isinstance(object[key], dict):
recursively_sort_opts(object[key])
elif isinstance(object[key], list):
recursively_sort_opts(object[key])
elif isinstance(object, list):
for element in object:
recursively_sort_opts(element)


def dict_hash(dictionary: dict[str, Any], dedent_help_strings: bool = True, sort_opts: bool = True) -> str:
"""
MD5 hash of a dictionary of configuration for click.
Sorted and dumped via json to account for random sequence of keys in the dictionary. Also it
implements a few corrections to the dict because click does not always keep the same sorting order in
options or produced differently indented help strings.
:param dictionary: dictionary to hash
:param dedent_help_strings: whether to dedent help strings before hashing
:param sort_opts: whether to sort options before hashing
"""
if dedent_help_strings:
dedent_help(dictionary)
if sort_opts:
recursively_sort_opts(dictionary)
# noinspection InsecureHash
dhash = hashlib.md5()
try:
Expand Down

0 comments on commit 2a58ada

Please sign in to comment.