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

Add record/replay support for overridden methods, type serializers #241

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

peterallenwebb
Copy link
Contributor

@peterallenwebb peterallenwebb commented Jan 26, 2025

Description

In previous versions, the record/replay mechanism did not support function overrides. If a recorded method on class A was overridden by an inheriting class B, calls to the override would not be recorded. This revision fixes that shortcoming.

This revision also allows a mashumaro SerializationStrategy to be registered so that "auto" recorded functions with complex parameters or return values can be handled with a minimum amount of effort.

Checklist

@cla-bot cla-bot bot added the cla:yes label Jan 26, 2025
Copy link

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2025

Codecov Report

Attention: Patch coverage is 91.30435% with 6 lines in your changes missing coverage. Please review.

Project coverage is 69.66%. Comparing base (3441e08) to head (af772dc).

Files with missing lines Patch % Lines
dbt_common/record.py 91.30% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
+ Coverage   69.09%   69.66%   +0.56%     
==========================================
  Files          52       52              
  Lines        3456     3511      +55     
==========================================
+ Hits         2388     2446      +58     
+ Misses       1068     1065       -3     
Flag Coverage Δ
unit 69.66% <91.30%> (+0.56%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@peterallenwebb peterallenwebb changed the title Add record/replay support for overriden methods. Add record/replay support for overridden methods, type serializers Jan 29, 2025
@peterallenwebb peterallenwebb marked this pull request as ready for review January 29, 2025 21:13
@peterallenwebb peterallenwebb requested a review from a team as a code owner January 29, 2025 21:13
Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

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

This looks great!
I think two things to things about later on:

  • write things out in the per thread fashion
  • think a bit about memory management(let's not blow up people's existing job because recording we hold in memory takes too much space). We can consider flush things to disk as a node finish.

def write(self) -> None:
with open(self.current_recording_path, "w") as file:
json.dump(self._to_dict(), file)
self.write_json(file)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am assuming we are going to write to the other folder structure we discussed in a later PR?

set_invocation_context({})
get_invocation_context().recorder = recorder

recorder.register_serialization_strategy(CustomType, CustomSerializationStrategy())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! I guess we can just maintain a file of type: serialization later on for all of the types we encounter?

def test_func(self, a: int) -> int:
return 2 * a

class RecordableSubclass(Recordable):
Copy link
Contributor

Choose a reason for hiding this comment

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

wonderful!

def test_func(self, a: int) -> int:
return 2 * a

class RecordableSubclass(Recordable):
Copy link
Contributor

Choose a reason for hiding this comment

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

I am assuming we have more than 2 layers(baseAdapter, sqlAdapter, SnowflakeAdapter), does it still work?(I think so but a bit harder to reason through, maybe consider expand this test a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, I also need to inject a modification to the subclasses own init_subclass function. I'll add that in the next revision.

@peterallenwebb peterallenwebb added this pull request to the merge queue Jan 30, 2025
Merged via the queue into main with commit 3956ae7 Jan 30, 2025
15 checks passed
@peterallenwebb peterallenwebb deleted the paw/record_overrides branch January 30, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants