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

Respect repr on fields when logging a dataclass #592

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Nov 13, 2024

Requested by @samuelcolvin.

I think it maybe makes sense to have a way for users to control this behavior more explicitly/independently of other use cases (e.g., via a magic __pydantic_logfire_dump__ method?). But this seems reasonable to me for now. Not sure if we need to be concerned about it being a breaking change, or need to provide a way to opt into it or something.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (dd6c380) to head (8a5019f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #592   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          133       133           
  Lines        10448     10452    +4     
  Branches      1430      1431    +1     
=========================================
+ Hits         10448     10452    +4     

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

@dataclass
class MyReprDataclass:
in_repr: int
not_in_repr: int = field(repr=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a complex object that would appear in the json schema.

then ensure it doesn't appear in the json schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, it does misbehave :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I think. And I check there was nowhere else we use the dataclasses.fields function, so I think it should be good now.

Copy link

cloudflare-workers-and-pages bot commented Nov 13, 2024

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8a5019f
Status: ✅  Deploy successful!
Preview URL: https://9245c40d.logfire-docs.pages.dev
Branch Preview URL: https://respect-repr-when-logging-da.logfire-docs.pages.dev

View logs

@Kludex Kludex enabled auto-merge (squash) November 14, 2024 09:28
@Kludex Kludex merged commit a316c91 into main Nov 14, 2024
17 checks passed
@Kludex Kludex deleted the respect-repr-when-logging-dataclass branch November 14, 2024 09:34
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.

dataclass fields with field(repr=False) should not be serialized/shown
4 participants