Skip to content

AttributeError: 'NoneType' object has no attribute 'strip' #432

@yourGuy

Description

@yourGuy

This occurs in ecommerce_integrations/shopify/customer.py in the sync_customer method. The current code attempts to fallback to email when name is missing, but doesn't handle the case where email is also None.

Steps to Reproduce:

Create a Shopify customer with no first_name, last_name, or email
Attempt to sync an order for this customer
Customer sync fails with AttributeError
Traceback:

File "apps/ecommerce_integrations/ecommerce_integrations/shopify/order.py", line 48, in sync_sales_order
customer.sync_customer(customer=shopify_customer)
File "apps/ecommerce_integrations/ecommerce_integrations/shopify/customer.py", line 29, in sync_customer
super().sync_customer(customer_name, customer_group)
File "apps/ecommerce_integrations/ecommerce_integrations/controllers/customer.py", line 41, in sync_customer
customer.insert(ignore_permissions=True)
File "apps/erpnext/erpnext/selling/doctype/customer/customer.py", line 117, in get_customer_name
self.customer_name = self.customer_name.strip()
AttributeError: 'NoneType' object has no attribute 'strip'
Proposed Fix:

In ecommerce_integrations/shopify/customer.py, add a fallback to use the customer ID when both name and email are missing:

python
def sync_customer(self, customer: dict[str, Any]) -> None:
"""Create Customer in ERPNext using shopify's Customer dict."""

customer_name = cstr(customer.get("first_name")) + " " + cstr(customer.get("last_name"))
if len(customer_name.strip()) == 0:
    customer_name = customer.get("email")
if not customer_name:  # Add this fallback
    customer_name = f"Customer {customer.get('id')}"

customer_group = self.setting.customer_group
super().sync_customer(customer_name, customer_group)

This ensures customer_name is never None when passed to ERPNext's Customer creation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions