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

Introduce a recursive cycle check when writing #345

Merged
merged 1 commit into from
Jan 10, 2023
Merged

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented May 16, 2022

I noticed that writing can blow up when there are recusrive objects that reference each other.
(For example, in HTTP.jl, Response and Request reference each other)
This PR proposes a simple API for the CompactContext and PrettyContext where
objectid of objects will be tracked recursively when writing and it's configurable
what should be written out when a recursive cycle is detected.

Custom contexts can "hook in" to this behavior by subtyping RecursiveCheckContext and
including the required fields (see docs for new context). Otherwise, there shouldn't
be any functional change to APIs in any way.

cc: @vilterp (oops, wrong ping the 1st time)

I noticed that writing can blow up when there are recusrive objects that reference each other.
(For example, in HTTP.jl, `Response` and `Request` reference each other)
This PR proposes a simple API for the `CompactContext` and `PrettyContext` where
`objectid` of objects will be tracked recursively when writing and it's configurable
what should be written out when a recursive cycle is detected.

Custom contexts can "hook in" to this behavior by subtyping `RecursiveCheckContext` and
including the required fields (see docs for new context). Otherwise, there shouldn't
be any functional change to APIs in any way.
@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #345 (df46bcd) into master (de16550) will decrease coverage by 0.19%.
The diff coverage is 96.29%.

@@            Coverage Diff             @@
##           master     #345      +/-   ##
==========================================
- Coverage   98.63%   98.44%   -0.20%     
==========================================
  Files           5        5              
  Lines         441      451      +10     
==========================================
+ Hits          435      444       +9     
- Misses          6        7       +1     
Impacted Files Coverage Δ
src/Writer.jl 97.60% <96.29%> (-0.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de16550...df46bcd. Read the comment docs.

@quinnj
Copy link
Member Author

quinnj commented May 19, 2022

@KristofferC or @fredrikekre, could I bug you to review here?

@quinnj quinnj merged commit 2219019 into master Jan 10, 2023
@quinnj quinnj deleted the jq/recursive branch January 10, 2023 18:21
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.

1 participant