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

Storing boolean value in a non-defined/string field #1065

Closed
mkrecek234 opened this issue Sep 5, 2022 · 7 comments
Closed

Storing boolean value in a non-defined/string field #1065

mkrecek234 opened this issue Sep 5, 2022 · 7 comments

Comments

@mkrecek234
Copy link
Contributor

Steps to reproduce:

  1. Create model with field: $model->addField('generic_field')
  2. Save a boolean value to that field $model->createEntity()->save(['generic_field' => true]).

Result:
Exception Field must not be boolean

Behaviour before = Expected behaviour: Was typecasted to null or 1 automatically.

@mkrecek234 mkrecek234 changed the title Storing boolean value in a non-defined field Storing boolean value in a non-defined/string field Sep 5, 2022
@mvorisek
Copy link
Member

mvorisek commented Sep 5, 2022

The fields are strictly typed and if type is null, string type is implied for BC.

Given this fact, the exception seems correct to me. Can we close this issue or why true should imply null or 1?

@mkrecek234
Copy link
Contributor Author

Before boolean was stored as "1" (true) or null (false) if stored in string field, now it throws an exception. Shouldn't it store as before?

@mvorisek
Copy link
Member

mvorisek commented Sep 5, 2022

Wdym by store?

In php, we store it natively - true / false, in database, we store it by 1 / 0. Everything seems to be correct to me, working and tested.

@mkrecek234
Copy link
Contributor Author

mkrecek234 commented Sep 5, 2022

Will try to make repro code - I saved a false value to a string field, and got "must not be boolean" as an exception. However, if you save a false boolean value to a string field it should convert it to null, shouldn't it? And true should be saved as 1 in a string field.

@mvorisek
Copy link
Member

mvorisek commented Sep 5, 2022

No, it should not, it is a type error. Other people will open an issue false is not converted to 0... You have the rights to reopen this issue in case you have some new evidence, but the problem you reported here is known & wanted behaviour.

@mvorisek mvorisek closed this as completed Sep 5, 2022
@mkrecek234
Copy link
Contributor Author

mkrecek234 commented Sep 5, 2022

This then is a BC break, as it was automagically converted before, wasn't it? I like automatic type conversions, but am fine either way. And I don't care if false is converted to "0" or null in a string, all fine.

@mvorisek
Copy link
Member

mvorisek commented Sep 5, 2022

Probably some fixed bug :)

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

No branches or pull requests

2 participants