-
Notifications
You must be signed in to change notification settings - Fork 94
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
Calling valid? within a custom type transform fn causes an StackOverflowError #240
Comments
Hi @timclemons how are you? I reproduce your report from my side and the problem is a mutual recursion hard to avoid here. Both Therefore, you can avoid the recursion by re-writing your transformer to include a nullable binding to (defn tai->utc
[_ {:keys [epoch nano time-basis] :as x}]
(binding [*transformer* nil]
(if (and (s/valid? ::instant x) (= :TAI time-basis))
{:epoch "Epoch converted"
:nano nano
:time-basis :UTC}
x))) When the transformer is called at spec-tools/src/spec_tools/core.cljc Line 407 in 65bb923
conform* when the s/valid call happen.
It is not elegant because you need to understand the internal workings of both |
@timclemons quick update, I had an idea about how to solve this issue... The PR attached here will disable the transformer variable when a transformer function is called. i think this is a reasonable constraint to avoid stackoverflows. Therefore, with this PR you do not need to use |
That PR looks like a sensible approach. Thanks for the work you put into this! |
Given a setup like the following:
Attempting to run
(st/encode ::instant val utc-xform)
on any valid ::instant value results in the transform function running recursively until a stack overflow occurs. Removing the call to valid? resolves this.Can we get around this? Seems like part of the point of using spec is being able to validate data incoming to functions like the transforms.
The text was updated successfully, but these errors were encountered: