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

Do not use null as default value #1265

Merged
merged 1 commit into from
Jan 18, 2021

Conversation

VincentLanglet
Copy link
Member

@VincentLanglet VincentLanglet commented Jan 13, 2021

Subject

I am targeting this branch, because BC.

getOptions is using array_key_exist so

$this->getOptions('field_type', DateTimeFilter::class)

will return null instead of DateTimeFiler::class when the type is guessed by our guesser.

This issue was reported on slack by someone using the master branch and he tried the fix for me.

Changelog

### Fixed
- Do not provide a default `null` `field_type` option for Filter

@VincentLanglet VincentLanglet requested a review from a team January 13, 2021 19:51
OskarStark
OskarStark previously approved these changes Jan 13, 2021
@VincentLanglet VincentLanglet requested a review from a team January 13, 2021 21:00
@franmomu
Copy link
Member

franmomu commented Jan 13, 2021

Looks like the problem is that field_type is not defined in

case 'datetime':
case 'datetime_immutable':
case 'vardatetime':
case 'datetimetz':
case 'datetimetz_immutable':
return new TypeGuess(DateTimeFilter::class, $options, Guess::HIGH_CONFIDENCE);
case 'date':
case 'date_immutable':
return new TypeGuess(DateFilter::class, $options, Guess::HIGH_CONFIDENCE);

I guess the $options['field_type]` should be added in both cases.

Either way, IMO a test should be added.

@VincentLanglet
Copy link
Member Author

Looks like the problem is that field_type is not defined in

case 'datetime':
case 'datetime_immutable':
case 'vardatetime':
case 'datetimetz':
case 'datetimetz_immutable':
return new TypeGuess(DateTimeFilter::class, $options, Guess::HIGH_CONFIDENCE);
case 'date':
case 'date_immutable':
return new TypeGuess(DateFilter::class, $options, Guess::HIGH_CONFIDENCE);

I guess the $options['field_type]` should be added in both cases.

It should instead rely on the default value like here: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Filter/DateFilter.php#L39

There is no reason to set null, instead we should set nothing and let the filter doing his work.

@franmomu
Copy link
Member

So, should we remove the rest of field_type from there?

@VincentLanglet
Copy link
Member Author

So, should we remove the rest of field_type from there?

That's a good point.

Other filters are setting the field_type because they were no default one.

For instance, the NumberFilter is not overriding the getFieldType method

    public function getFieldType()
    {
        return $this->getOption('field_type', TextType::class);
    }

I'll fix this.

@VincentLanglet
Copy link
Member Author

By the way, in SonataAdmin we're not using getFieldType and getFieldOption so this could be removed from the FilterInterface.

Rely on default value instead
@VincentLanglet
Copy link
Member Author

@franmomu Tests are updated to check that null is not passed.
And I removed the useless field_type.

@VincentLanglet VincentLanglet merged commit 443773b into sonata-project:3.x Jan 18, 2021
@VincentLanglet VincentLanglet deleted the fixGuessType branch January 18, 2021 09:17
VincentLanglet added a commit that referenced this pull request Jan 20, 2021
* Do not pass field_type to Filter (#1265)

Rely on default value instead

* Add composite primary keys tests

* Fix pager for composite id

* Add tests

* Remove trademarks

* Bump symfony/panther to 0.9 (#1273)

* Applied fixes from FlintCI (#1274)

* DevKit updates for 3.x branch (#1275)

* DevKit updates

* Fix lint

Co-authored-by: Vincent Langlet <vincentlanglet@hotmail.fr>

Co-authored-by: Vincent Langlet <VincentLanglet@users.noreply.github.com>
Co-authored-by: Vincent Langlet <vincentlanglet@hotmail.fr>
Co-authored-by: Fran Moreno <franmomu@gmail.com>
Co-authored-by: Sullivan SENECHAL <soullivaneuh@gmail.com>
Co-authored-by: Sonata CI <thomas+ci@sonata-project.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants