action-scheduler icon indicating copy to clipboard operation
action-scheduler copied to clipboard

PHP Fatal error: Uncaught RuntimeException: Error saving action: `ActionScheduler_Action::$args` too long

Open saad-siddique opened this issue 2 years ago • 5 comments

Hey,

A few of our plugin users (Pro version of the Automator plugin) have reported this issue. We are using v3.4.0 of the Action Scheduler library in our plugin. Has anyone else reported the problem?

"require": {
    "woocommerce/action-scheduler": "^3.4.0"
  },

Can this hardcoded extended_args varchar(8000) limit be changed to longext instead?

https://github.com/woocommerce/action-scheduler/blob/3fe1e79f031c7300e5c60c61f732b358552ddc16/classes/schema/ActionScheduler_StoreSchema.php#L59

[02-Sep-2022 08:54:31 UTC] PHP Fatal error: Uncaught RuntimeException: Error saving action: ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than 8000 characters when encoded as JSON. in /wp-content/plugins/xxxxxx/vendor/woocommerce/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php:86

Stack trace:

#0 /wp-content/plugins/xxxxxx/vendor/woocommerce/action-scheduler/classes/ActionScheduler_ActionFactory.php(177): ActionScheduler_DBStore->save_action(Object(ActionScheduler_Action))

#1 /wp-content/plugins/xxxxxx/vendor/woocommerce/action-scheduler/classes/ActionScheduler_ActionFactory.php(84): ActionScheduler_ActionFactory->store(Object(ActionScheduler_Action))

#2 /wp-content/plugins/xxxxxx/vendor/woocommerce/action-scheduler/functions.php(36): ActionScheduler_ in /wp-content/plugins/xxxxxx/vendor/woocommerce/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php on line 86

saad-siddique avatar Sep 12 '22 14:09 saad-siddique

This really needs to be fixed. Not necessarily by changing the column type, another option would be to implement a separate meta table for scheduler actions, and that does look reasonable enough to me. I've seen the discussion in https://github.com/woocommerce/action-scheduler/issues/418, including using postmeta for long actions. As a heavy user of Uncanny Automator plugin, I can confirm that this limit is a problem. Besides that, the error says that the 8k chars limit is there to ensure indexing, but it's args column that is indexed, not extended_args which isn't indexed, see below. tbl_struct

bugnumber9 avatar Sep 12 '22 17:09 bugnumber9

Hi @saad-siddique @bugnumber9,

Thanks for taking the time to file this issue.

Changing the size of the column is probably not the best way to go, and the alternatives are not so trivial to implement, as described in #418, which basically dealt with this same problem.

I understand the workarounds or suggestions in #418 might not be universally applicable, so I'm filing this issue as an enhancement request in the hopes we can get to it soon. In the mean time, if anyone is interested in submitting a PR to address this, we'd be more than happy to take a look.

Thanks again!

jorgeatorres avatar Sep 15 '22 17:09 jorgeatorres

@jorgeatorres, Thank you for taking the time to reply to this issue. I've created a PR to address this issue here: https://github.com/woocommerce/action-scheduler/pull/855/files. It's a straightforward change, and I don't think extended_args references in the code need other modifications. It should work as is if you merge it. But of course, I'll leave it up to you to decide.

saad-siddique avatar Sep 15 '22 17:09 saad-siddique

As far as I've been looking into this, there's more - there's at least protected static $max_args_length = 8000; in /classes/data-stores/ActionScheduler_DBStore.php unless I've missed something else.

bugnumber9 avatar Sep 15 '22 20:09 bugnumber9

As a workaround, it might be beneficial to store large data in a different table and then have an ID as part of the argument. You can then fetch this data from the action itself. If we change the type from varchar to text, then it won't be indexable anymore (which seems like some shops do use).

vedanshujain avatar Sep 01 '23 10:09 vedanshujain