-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Explanation
When a property in the constructor is not filled and the form type has no validation error related, empty data auto-fill may fail silenciously.
SwagIndustries\Melodiia\Doctrine\DoctrineDataStore::save(): Argument #1 ($model) must be of type object, null given, called in /home/manager-app/vendor/swag-industries/melodiia/src/Crud/Controller/Create.php on line 68
Example
Let's take as an example this registration form:
use SwagIndustries\Melodiia\Form\AbstractType;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', TextType::class, [
'constraints' => [new NotBlank(), new Email()],
])
->add('password', TextType::class, ['constraints' => new NotBlank()])
->add('username', TextType::class) // optional
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('data_class', User::class);
}
}With the following User model:
class User
{
public function __construct(
private string $email,
private string $password,
private string $username // Required!!
) {}
}If you provide the following data to the API:
{
"email": "acme@swag.industries",
"password": "somepass"
}Then you will end up with a super weird (but normal because a parameter is missing) 500 error, instead of a validation error.
Solution
I have no out of the fryer option for now. Adding a log would be nice for sure.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels