You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because the WC_Data class stores a reference to the data store, when any sub-class instance is saved to cache, the data store gets saved with it. This isn't normally an issue unless the underlying data store instance is setup to properly handled being being serialized.
For instance, I created a custom data store for orders. To make the data store more testable, it accepts a wpdb instance in its constructor that it sets as a property and uses for CRUD operations. This caused the following bug:
I first create an order:
WC_Order_Factory::get_order() is called to create a new order.
The order is automatically serialized and saved to cache, within this serialization is a reference to the WC_Data_Store, which includes my order data store, which in turn includes its reference to wpdb.
On a subsequent request, I go to update the order
WC_Order_Factory::get_order() is called to get the order
The order is automatically unserialized with references to the WC_Data_Store, my order data store, and the wpdb instance with properties from the first request.
Updates are made to the order and then it is saved via $order->save()
Because that chain is of objects is pointing to the wpdb instance that hasn't yet connected on this request, the query fails.
While I could avoid serializing the wpdb instance in my order data store, I think it makes most sense to break the serialization chain within the WC_Data_Store instance.
The text was updated successfully, but these errors were encountered:
Because the
WC_Data
class stores a reference to the data store, when any sub-class instance is saved to cache, the data store gets saved with it. This isn't normally an issue unless the underlying data store instance is setup to properly handled being being serialized.For instance, I created a custom data store for orders. To make the data store more testable, it accepts a
wpdb
instance in its constructor that it sets as a property and uses for CRUD operations. This caused the following bug:I first create an order:
WC_Order_Factory::get_order()
is called to create a new order.WC_Data_Store
, which includes my order data store, which in turn includes its reference towpdb
.On a subsequent request, I go to update the order
WC_Order_Factory::get_order()
is called to get the orderWC_Data_Store
, my order data store, and thewpdb
instance with properties from the first request.$order->save()
wpdb
instance that hasn't yet connected on this request, the query fails.While I could avoid serializing the
wpdb
instance in my order data store, I think it makes most sense to break the serialization chain within theWC_Data_Store
instance.The text was updated successfully, but these errors were encountered: