News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

$smcFunc returning 'Database value you're trying to insert doesn't exist'

Started by tjbalon, July 27, 2018, 02:56:45 PM

Previous topic - Next topic

tjbalon

Hello,

My website operates a script that runs every few minutes to update profile statuses of different platforms. In that, we fetch 100 users at a time and update their status and details for steam. We run an smcFunc query that updates their information in our database.

It will update a bunch of users, but then randomly return:

        <div id="fatal_error">
                <div class="cat_bar">
                        <h3 class="catbg">
                                An Error Has Occurred!
                        </h3>
                </div>
                <div class="windowbg">
                        <span class="topslice"><span></span></span>
                        <div class="padding">The database value you're trying to insert does not exist: steampic</div>
                        <span class="botslice"><span></span></span>
                </div>
        </div>
        <div class="centertext"><a href="javascript:history.go(-1)">Back</a></div>r


The column does exist, and it just worked for say 200 other people, not sure why it would randomly die out. (Also, the ID of the member it fails on changes each time).

Any advice would be appreciated,  I'm not sure all the conditions when this occurs.

Arantor

So wherever whatever value is being put into the replacement for 'steampic', it is null rather than an actual value.

tjbalon

Quote from: Arantor on July 27, 2018, 02:58:01 PM
So wherever whatever value is being put into the replacement for 'steampic', it is null rather than an actual value.

It is strangely replacing the wrong data in people's columns.

But yeah, looks like it was null, as an ex for print_r:
[2018-07-27 15:08:17] [I] 1
[2018-07-27 15:08:17] [I] complete
[2018-07-27 15:08:17] [I] Information for: 6076. Updating database with latest information.
Array
(
    [id_member] => aaaa
    [real_name] => aaaaaa
    [id_group] => 00
    [steamid] => aaaa
    [steampic] =>
    [steamname] =>
    [steamstatus] => Offline
)

Arantor

Yup, the error indicates that null was trying to be inserted into the database, which $smcFunc doesn't permit.

tjbalon

Quote from: Arantor on July 27, 2018, 03:19:45 PM
Yup, the error indicates that null was trying to be inserted into the database, which $smcFunc doesn't permit.

Looks like steam decided after GDPR, just let's return an empty array for deleted accounts, no indication. So it's borked like all of our stuff with just 1 deleted steam account in 12,000 people. It broke  July 25, 2 mon after GDPR, guessing that's when they kill the data off the API.

Trying to figure out what to do about that, thanks for the help Arantor. Wouldn't have guessed that.

tjbalon

General question here for ya then:

We use this:
$steamKey = array_search($dbUser['steamid'], array_column($steamData, 'steamid'));


This produces the index of the steam user we're going to get their data off of. The issue however, is if one user is deleted on steam and returns {} in their API response, that dead data in the array_column returns a smaller array than we have data. IE:

Array
(
    [0] => 76561198841321
    [1] => 765611988123
    [2] => 76561198123
    [3] => 765611912321
    [4] => 7656119123123
    [5] => 7656119881231
    [6] => 7656119881312
    [7] => 765611988441231
    [8] => 76561198154432
    [9] => 76561198841123
)


So with one random missing index, it throws everything off. Is there function you can think like array_column that if in the JSON the value we're looking for [steamid] in this case, we can put in a random 0 or nil data? Right now we have a 'ghetto' fix so to speak, but haven't been able to think of a better approach:
    foreach($steamData as $steamIndex=>$steamProfile){
        if(!array_key_exists('steamid', $steamProfile))
            $steamData[$steamIndex]['steamid'] = 0;
    }


Thought API's were supposed to be consistent, and not randomly return nil values but O:) silly valve.

Arantor


tjbalon


Advertisement: