Issue: Some fields should not be NULL in openedx/ecommerce

In ecommerce/extensions/refund/

order_line and refund should not be NULL in class RefundLine
These two fields are essential to construct the class, which are defined as foreign keys, which will be deleted with CASCADE effect.

If these two fields are NULL, it means that the data may already be corrupted. To prevent this from happening, we can add null=False in these fields to protect the data integrity

class RefundLine(StatusMixin, TimeStampedModel):
    """A refund line, used to represent the state of a single item as part of a larger Refund."""
    refund = models.ForeignKey(
        'refund.Refund', related_name='lines', verbose_name=_('Refund'), on_delete=models.CASCADE
    order_line = models.ForeignKey(
        'order.Line', related_name='refund_lines', verbose_name=_('Order Line'), on_delete=models.CASCADE

Similarly, user and order should not be NULL in class Refund. The refund will be created from the order and order_lines. If the refund does not have an order or the order’s user is NULL, which will cause exceptions in future references. We can add a not null constraint for this.

class Refund(StatusMixin, TimeStampedModel):
    """Main refund model, used to represent the state of a refund."""
    order = models.ForeignKey('order.Order', related_name='refunds', verbose_name=_('Order'), on_delete=models.CASCADE)
    user = models.ForeignKey('core.User', related_name='refunds', verbose_name=_('User'), on_delete=models.CASCADE)

I can work on the PR for this issue, please let me know your thoughts. Thanks!


Apologies for the delay, I was just alerted to your post, thank you for finding these, they do look like missing constraints. For most Open edX projects PRs are a great way to contribute, however we are in the process of deprecating this ecommerce service and will only be applying critical security fixes while we build the replacement; you can learn more about that process and the new system in this post. Thank you again, and we would love your input and contributions to all parts of Open edX.

1 Like

Hi @bjh

Thank you for your reply. I actually find similar issues in the edx-platform repo too. I just posted here. Could you take a look? I can create PRs for this if needed. Thanks!