jethro-pmm icon indicating copy to clipboard operation
jethro-pmm copied to clipboard

Invalid argument supplied for foreach(), Line 685 of db_object.class.php

Open jefft opened this issue 2 years ago • 6 comments

I'm seeing errors in the logs triggered by viewing a particular person. There is no visible problem in the HTML page.

Invalid argument supplied for foreach()
Line 685 of /home/jethro/code/2.32.0/include/db_object.class.php

USER:       1
REFERER:   
USER_AGENT: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/[105.0.0.0](http://105.0.0.0/) Safari/537.36

REQUEST:
Array
(
    [view] => persons
    [personid] => 492
)


BACKTRACE:
Array
(
    [0] => Array
        (
            [file] => /home/jethro/code/2.32.0/db_objects/person.class.php
            [line] => 322
            [function] => printFieldValue
            [class] => db_object
            [type] => ->
            [args] => Array
                (
                    [0] => history
                    [1] =>
                )

        )

    [1] => Array
        (
            [file] => /home/jethro/code/2.32.0/templates/view_person.template.php
            [line] => 391
            [function] => printFieldValue
            [class] => Person
            [type] => ->
            [args] => Array
                (
                    [0] => history
                )

        )

    [2] => Array
        (
            [file] => /home/jethro/code/2.32.0/views/view_3_persons.class.php
            [line] => 34
            [args] => Array
                (
                    [0] => /home/jethro/code/2.32.0/templates/view_person.template.php
                )

            [function] => include
        )

    [3] => Array
        (
            [file] => /home/jethro/code/2.32.0/include/system_controller.class.php
            [line] => 186
            [function] => printView
            [class] => View_Persons
            [type] => ->
            [args] => Array
                (
                )

        )

    [4] => Array
        (
            [file] => /home/jethro/code/2.32.0/templates/main.template.php
            [line] => 113
            [function] => printBody
            [class] => System_Controller
            [type] => ->
            [args] => Array
                (
                )

        )

    [5] => Array
        (
            [file] => /home/jethro/code/2.32.0/include/system_controller.class.php
            [line] => 128
            [args] => Array
                (
                    [0] => /home/jethro/code/2.32.0/templates/main.template.php
                )

            [function] => require
        )

    [6] => Array
        (
            [file] => /home/jethro/code/2.32.0/index.php
            [line] => 58
            [function] => run
            [class] => System_Controller
            [type] => ->
            [args] => Array
                (
                )

        )

)

jefft avatar Sep 04 '22 23:09 jefft

This error is not new to 2.32.0. I've seen it in logs for a 2.31.x instance too.

jefft avatar Sep 04 '22 23:09 jefft

Does the person have any history? #816 might help, by ensuring that an array is returned in that case. What happens if you try updating the person?

vanoudt avatar Sep 05 '22 01:09 vanoudt

Personally, I'm not sure serialising something like history is the best way to go. I'd rather each audit line be stored atomically in a history table. But that would be another pull request! I suspect that, at least in my case, the history field got corrupted or blanked somehow, perhaps a bug upon saving? If using a history table, at most the offending transaction would be lost, rather than the entire history!

vanoudt avatar Sep 05 '22 01:09 vanoudt

@vanoudt yes you're right. The history is blank ('', not null), and in fact there is a user-visible artifact: the history tab says An error occurred. Please contact your system administrator for help..

There's loads of blank histories in this particular instance, so perhaps it was an import gone wrong (not the CSV import - it correctly sets a minimal history). Normally, every person would have at least a 'created' event:

a:1:{i:1437453070;s:7:"Created";}

In another instance, I've seen this error when the history appears possibly corrupted by character encoding issues. If I edit and save the user, I get unserialize(): Error at offset 415 of 667 bytes. Partially anonymized history:

 # mysql -sBe "select history from _person where id=2790;"
history
a:6:{i:1462581620;s:7:"Created";i:1462581736;s:112:"Updated by XXXXX XXXXX (#1)\nEmail changed from "" to "[email protected]"\nOccupation changed from "" to "pastor"";i:1462582586;s:127:"Updated by XXXXX XXXXX (#1)\nWork Tel changed from "" to "6555-XXXX"\nChurch - Current changed from "" to "Christian Life Centre"";i:1486078034;s:81:"Updated by XXXXX XXXXX (#1)\nContact Remarks changed from "" to "3–5 XXXXXXX St"";i:1486078990;s:119:"Updated by XXXXX XXXXX (#1)\nContact Remarks changed from "3–5 Ken\n3–5 XXXXXXX St"";i:1487290016;s:72:"Updated by XXXXX XXXXX (#1)\nMobile Tel changed from "" to "XXXXX XXX XXX"";}

jefft avatar Sep 05 '22 01:09 jefft

Hmmm - interesting! I hadn't thought about character encoding issues!

vanoudt avatar Sep 05 '22 02:09 vanoudt

Personally, I'm not sure serialising something like history is the best way to go. I'd rather each audit line be stored atomically in a history table. But that would be another pull request! I suspect that, at least in my case, the history field got corrupted or blanked somehow, perhaps a bug upon saving? If using a history table, at most the offending transaction would be lost, rather than the entire history!

Yes, I agree, for various reasons it'd be better to have it stored differently. Would need to think carefully about the upgrade path though.

tbar0970 avatar Sep 05 '22 04:09 tbar0970