Problem/Motivation

The helper function commerce_line_item_new() does not require a bundle (type) to be passed, causing EntityMalformedException if saved.

$stub = commerce_line_item_new();
commerce_line_item_save($stub);

Proposed resolution

Do not default $type argument to an empty string, force sending bundle type.

Remaining tasks

PATCH!

CommentFileSizeAuthor
#1 commerce_line_item_can-2538772-1.patch644 bytesmglaman

Comments

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new644 bytes

Patch.

rszrama’s picture

Category: Bug report » Task
Status: Needs review » Closed (won't fix)

I'm inclined to leave this as is. The same is true for all of our *_new() helper functions - they really exist just to initialize values. The caller is really responsible for setting all of the appropriate values prior to saving the object, we just don't force a type to be passed to this helper function. For example, you wouldn't be able to save a product without setting a SKU, but we don't even accept a SKU in the commerce_product_new() signature.

Happy to reconsider this, but I'm not sure it's worth changing the general philosophy of Commerce 1.x w/ respect to not being particularly defensive in our API functions at this point.