yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

Table schema cache errors when upgrading from 2.0.12 to 2.0.15 #16640

Open tehmaestro opened 6 years ago

tehmaestro commented 6 years ago

What steps will reproduce the problem?

Hi, I'm trying to upgrade our backend from version 2.0.12 to 2.0.15.

We have 4 backend machines, running Yii2 REST APIs and when I deploy the upgrade, from 2.0.12 to 2.0.15 , the machines are upgraded one by one. Also, I use yii2-redis for caching and MySQL as a database.

When running the deployment, the machines still running 2.0.12 throw a Trying to get property of a non-object. I believe this is because the caching structure for the table schemas has changed. In 2.0.15, there is a top-level schema key in the JSON that is being cached.

Version 2.0.15 is overwriting the cache with the new structure.

What is the expected result?

The backend machines should work normally, no errors.

What do you get instead?

I get a Trying to get property of a non-object in ActiveRecord:404

Thrown on 2.0.12 instances.

name: "PHP Notice",
message: "Trying to get property of non-object",
code: 8,
type: "yii\base\ErrorException",
file: "project\vendor\yiisoft\yii2\db\ActiveRecord.php",

Additional info

Might be related to https://github.com/yiisoft/yii2/issues/15117 . Not sure if that last fix works, I only tried 2.0.15.1

Q A
Yii version 2.0.12
PHP version 7.0.15
Operating system Linux

2.0.12

[
    {
        "schemaName": null,
        "name": "user_profile",
        "fullName": "user_profile",
        "primaryKey": [
            "id"
        ],

2.0.15

[
    {
        "schema": {
            "schemaName": null,
            "name": "user_profile",
            "fullName": "user_profile",
            "primaryKey": [
                "id"
            ],
yii-bot commented 6 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

samdark commented 6 years ago

Please try code from master.

tehmaestro commented 6 years ago

Thanks for your reply. I did try master and I still get the error. How I tested:

1) Checkout master, make some api requests, get some cached data in Redis 2) Checkout yii-update, composer install dev-master, make some api requests, get some cached data in Redis 3) Back to master, composer install 2.0.12, make some api requests -> error

If I flush the redis database, everything goes back to working as expected,

tehmaestro commented 5 years ago

Hi, so how can I tackle this? I've got multiple API machines in a load balanced environment, so my machines will get the update one at a time. Should I just use another DB from Redis cache? Or is this considered a bug? Thank you.

samdark commented 5 years ago

Looks like cache structure was changed and UPGRADE is missing the fact. Adding another instance of Redis and setting new code to use it should be a good solution. Old code will use old cache, new code will use new cache. Make sure that schema cache only is set to use new Redis instance since primary cache should stay shared as it was.