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

Fix compute_hash #450

Merged
merged 5 commits into from
Nov 27, 2019
Merged

Fix compute_hash #450

merged 5 commits into from
Nov 27, 2019

Conversation

mdrichardson
Copy link
Contributor

@mdrichardson mdrichardson commented Nov 26, 2019

With compute_hash as:

def compute_hash(self, obj: object) -> str:
    # TODO: Should this be compatible with C# JsonConvert.SerializeObject ?
    return str(obj)

...the hashes always return as something like "DialogStack at memoryAddressXYZ". If the DialogStack changes (dialogs added/removed), the memory address doesn't change, so the hash appears to be the same and changes are not written.

With:

def compute_hash(self, obj: object) -> str:
    return str(Pickler().flatten(obj))

...the whole DialogStack would get serialized and changes are correctly detected.


This wasn't detected because MemoryStorage manipulates the objects in memory, anyway and doesn't actually need to call MemoryStorage.write(). With persistent storage, write wasn't being called enough and things like ConversationState weren't actually updating, preventing users from progressing through WaterfallDialogs.

@mdrichardson mdrichardson requested a review from axelsrz November 26, 2019 19:23
@@ -24,8 +25,7 @@ def is_changed(self) -> bool:
return self.hash != self.compute_hash(self.state)

def compute_hash(self, obj: object) -> str:
# TODO: Should this be compatible with C# JsonConvert.SerializeObject ?
return str(obj)
return str(Pickler().flatten(obj))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! This is so important that I'm surprised that didn't blow up earlier

@axelsrz axelsrz merged commit 2b38e87 into master Nov 27, 2019
@axelsrz axelsrz deleted the mdrichardson-patch-1 branch November 27, 2019 23:27
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

Successfully merging this pull request may close these issues.

2 participants