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

Fix strict types in App::getTag() #1541

Merged
merged 13 commits into from
Dec 13, 2020

Conversation

PhilippGrashoff
Copy link
Collaborator

App::encodeHTML() expects a string as parameter. In App::getTag() its called, and I was able to produce a type error by adding totals to a table.

Here is the fixed version with typecast, note the marked zeros, they are what causes the issue with non-fixed version. The last row is added by Table::addTotals(), which calls App::getTag();

Bildschirmfoto von 2020-11-20 20-31-07

Without the fix, this error is produced:

Bildschirmfoto von 2020-11-20 20-31-24

@mvorisek
Copy link
Member

we want to AVOID explicit casts as much as possible - you should cast to string on data side - so no from my side

post usecase/steps to reproduce

@mvorisek
Copy link
Member

closing as no response

@mvorisek mvorisek closed this Nov 27, 2020
@PhilippGrashoff
Copy link
Collaborator Author

can you please reopen this one? I am quite busy and will provide a test case. Just closing an issue after two days isn't very polite.

@mvorisek mvorisek reopened this Nov 27, 2020
@mvorisek
Copy link
Member

reopened, but keep in mind that I will be very against solving this like you propose ;-)

@PhilippGrashoff
Copy link
Collaborator Author

Thanks for reopening. Well, there has to be some typecast to string somewhere it seems. Its logical that table totals are int/float, and somewhere along the stack trace they need to by cast to string. I didn't find any demo with numeric table totals, otherwise I'd guess they would fail.

@mvorisek
Copy link
Member

mvorisek commented Nov 28, 2020

revert your fix and update /demos/collection/table.php demo to replicate

@mkrecek234
Copy link
Contributor

Have the same issue with a simple model with field of 'type'=>'money'. The following table throws the same error as above:
`$regiontable = \atk4\ui\Table::addTo($app);
$regiontable->setModel($groupmodelsplit, false);

$regiontable->addColumn('continent');
$regiontable->addColumn('turnover_LTM', [\atk4\ui\Table\Column\Money::class]);

$regiontable->addTotals(['continent' => 'Totals:', 'turnover_LTM' => ['sum']]);`

@mvorisek
Copy link
Member

mvorisek commented Dec 1, 2020

@mkrecek234 please submit a PR with modified demo with this and only this isses, I will look/fix

@ibelar
Copy link
Contributor

ibelar commented Dec 7, 2020

@PhilippGrashoff - You should probably type cast the value inside Table\Column\getTotalsCellHtml() method:

    public function getTotalsCellHtml(Field $field, $value)
    {
        return $this->getTag('foot', (string) $this->getApp()->ui_persistence->typecastSaveField($field, $value));
    }

The bug can be reproduce inside /demos/collection/table.php when changing the 'salary' field from money to integer type.

@PhilippGrashoff
Copy link
Collaborator Author

Well, the question is if we use this fix or start refactoring Persistence/UI now. WDYT? We definitely should fix this error on Table totals soon.

@mvorisek mvorisek changed the title Add (string) typecast to encodeHTML() call in App::getTag() Fix strict types in App::getTag() Dec 11, 2020
@mvorisek mvorisek force-pushed the string_typecast_in_getTag branch from c53fef8 to 060aee3 Compare December 11, 2020 17:12
@mvorisek mvorisek force-pushed the string_typecast_in_getTag branch from 6d4914c to 92f89dd Compare December 11, 2020 17:13
@mvorisek
Copy link
Member

@PhilippGrashoff does this solve your issue?

@mvorisek mvorisek force-pushed the string_typecast_in_getTag branch from 3f57802 to 508debb Compare December 11, 2020 17:36
@ibelar ibelar mentioned this pull request Dec 11, 2020
@PhilippGrashoff
Copy link
Collaborator Author

Hi, will test, but looks like the proper place to fix this.

@@ -185,6 +185,15 @@ public function setModel(Model $model)
*/
public function setSource(array $data, $fields = null)
{
// ID with zero value is not supported, fix the data
if (isset($data[0])) {
Copy link
Member

@mvorisek mvorisek Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgehristov because of atk4/data#806 when validation is triggered.

I am not sure with this. We can switch to mandatory or allow zero IDs for non SQL persistences only.

Do you know, if zero as ID is actually a problem with some DB engine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce http://sqlfiddle.com/#!9/d28469/1 - at least with MySQL zero is understood as empty ID and AI is applied.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@mvorisek mvorisek Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with last fix I think we can keep "required" (and thus reject zero IDs)

/cc @DarkSide666 @georgehristov

@mvorisek mvorisek removed the RTM label Dec 11, 2020
@mvorisek mvorisek force-pushed the string_typecast_in_getTag branch from 563cc28 to faf1f6a Compare December 11, 2020 23:26
@mvorisek mvorisek added the RTM label Dec 11, 2020
@mvorisek mvorisek force-pushed the string_typecast_in_getTag branch from faf1f6a to 1724f83 Compare December 11, 2020 23:29
@mvorisek mvorisek merged commit 3cc39a6 into atk4:develop Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants