dj-stripe / dj-stripe

dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
https://dj-stripe.dev
MIT License
1.56k stars 474 forks source link

Unsupported unicode escape sequence when migrating the stripe account #2029

Closed agusmakmun closed 2 months ago

agusmakmun commented 2 months ago

Describe the bug

I'm trying to migrate the stripe account from Singapore to United Arab Emirate, and having problem while trying to sync the data from stripe to the database. Where the character ' is exist before the {"bacs_de.. text. and it's not a valid json text, and causing an error while saving to the JSONField.

image

image

To Reproduce

  1. Ensure you already have the old stripe data that saved in Django db from old account.
  2. Try to change the stripe account credentials from Singapore/America to United Arab Emirate.
  3. Try to do the sync data from new stripe account, you can use the python manage.py djstripe_sync_models command or use the below:
from django.core.management.base import BaseCommand
from djstripe.models import Product, Plan, Price

class Command(BaseCommand):
    """Sync packages for product, prices (and plans) from stripe."""

    help = "Sync packages for product, prices (and plans) from stripe."

    def handle(self, *args, **options):
        for product_data in Product.api_list():
            product = Product.sync_from_stripe_data(product_data)
            self.stdout.write(f"Synchronized product {product.id}")

        for price_data in Price.api_list():
            price = Price.sync_from_stripe_data(price_data)
            self.stdout.write(f"Synchronized price {price.id}")

        for plan_data in Plan.api_list():
            plan = Plan.sync_from_stripe_data(plan_data)
            self.stdout.write(f"Synchronized plan {plan.id}")

Software versions

agusmakmun commented 2 months ago

This happen because of have unicode character that saved in the company name:

import stripe
stripe.Account.retrieve("acct_xxxx")

image

It solved the problem after we renamed it.

image