Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data_Store gets serialized/cached with WC_Data objects #13636

Closed
prettyboymp opened this issue Mar 16, 2017 · 0 comments · Fixed by #13637
Closed

Data_Store gets serialized/cached with WC_Data objects #13636

prettyboymp opened this issue Mar 16, 2017 · 0 comments · Fixed by #13637
Labels
type: bug The issue is a confirmed bug.
Milestone

Comments

@prettyboymp
Copy link
Contributor

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:

  1. WC_Order_Factory::get_order() is called to create a new order.
  2. 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

  1. WC_Order_Factory::get_order() is called to get the order
  2. 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.
  3. Updates are made to the order and then it is saved via $order->save()
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants