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
required_without does not work with pointers #483
Comments
Hello!
I get panic:
Usually in http frameworks the request is a pointer.
|
@tbe did #484 fix your issue? Because I still seem to be experiencing the problem that you identified (seeing it on the package main
import (
"gopkg.in/go-playground/validator.v9"
"fmt"
)
func main() {
v:=validator.New()
result := v.Struct(foo{A: &emptystruct{}})
if result != nil {
fmt.Println(fmt.Sprintf("Unexpected Error: %s", result))
}
result = v.Struct(bar{A: "somevalue"})
if result != nil {
fmt.Println(fmt.Sprintf("Unexpected Error: %s", result))
}
}
type foo struct {
A *emptystruct `validate:"required"`
B *emptystruct `validate:"required_without_all=A C"`
C *emptystruct
}
type bar struct {
A string `validate:"required"`
B string `validate:"required_without_all=A C"`
C string
}
type emptystruct struct {
} gives the error
The fact that this does not also output a failure for |
@leafduo @crathjen @tbe I don't think the fixed worked either.
fails on 9.29.1 |
@johndww +1, still failing on 9.29.1. |
sorry that I have not been able to take a look at this, super busy with work right now. If anyone can help with the debugging and a PR it would be very appreciated :) |
#484 fixed panicking when the variable to validate is pointer, as in Line 8715 in 556b9da
But it did not fix the problem of Lines 96 to 159 in 556b9da
According to code above, any pointer with validator other than @deankarn can you shed some light? BTW, in the test code, Line 8717 in 556b9da
Line 8762 in 556b9da
|
Maybe #510 will fix this issue? |
For context how other validations work with pointers is that they are dereferenced prior to validation, but since the value is nil then there's nothing to dereference. I think another exception may be necessary like I like #510 but it's unfortunately a breaking change. |
I released a bunch of fixes today including all |
So with the latest version, the issue is not fully resolved. |
I believe I've properly corrected the issues now and released in:
please let me know if this resolves your issues :) P.S. I highly recomment updating to v10 |
Hello @deankarn |
@melonaerial can you please open a new issue next time 🙏 it's hard discussing in a closed and unrelated thread. I'm not 100% sure what you're trying to accomplish? doesn't |
Hi @deankarn I'm not sure it works when you have mulitple validation tags. Please run: |
Package version eg. v8, v9:
v9
Issue, Question or Enhancement:
required_without
does not work with pointersCode sample, to showcase or reproduce:
Playground: https://play.golang.org/p/5hpXOfDJU4V
The text was updated successfully, but these errors were encountered: