-
Notifications
You must be signed in to change notification settings - Fork 133
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
Handles partials in source code hash #1116
Conversation
This is a stop gap measure to handle partials for the CacheAdapter. I put the change here rather than in the source hash function, since for now it appears that this behavior is specific to the cache adapter..
439caa1
to
78443f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks nice. We can merge it.
@@ -376,7 +377,10 @@ def run_to_execute_node( | |||
if node_name not in self.cache_vars: | |||
return node_callable(**node_kwargs) | |||
|
|||
node_hash = graph_types.hash_source_code(node_callable, strip=True) | |||
source_of_node_callable = node_callable | |||
while isinstance(source_of_node_callable, partial): # handle partials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits, looks good
@@ -376,7 +377,10 @@ def run_to_execute_node( | |||
if node_name not in self.cache_vars: | |||
return node_callable(**node_kwargs) | |||
|
|||
node_hash = graph_types.hash_source_code(node_callable, strip=True) | |||
source_of_node_callable = node_callable | |||
while isinstance(source_of_node_callable, partial): # handle partials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool -- can make it into a function for clarity: get_original_function(func: Callable)
+ test, but this is good
@@ -138,3 +165,49 @@ def test_commit_nodes_history(hook: CacheAdapter): | |||
# need to reopen the hook cache | |||
with shelve.open(hook.cache_path) as cache: | |||
assert cache.get(CacheAdapter.nodes_history_key) == hook.nodes_history | |||
|
|||
|
|||
def test_partial_handling(hook: CacheAdapter, node_a_partial: node.Node): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if the func-derivation is a function then this one is less necessary (although still nice to have), and we can test that/get more confidence.
This is a stop gap measure to handle
partials for the CacheAdapter.
Changes
.func
attribute on a callable.How I tested this
This code now works:
Notes
Checklist