Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix file not found error on populatedb when CWD is not the project root

NyanKiyoshiae7b51d062bd
diff --git a/saleor/core/management/commands/populatedb.py b/saleor/core/management/commands/populatedb.py
index a99f371003..907915782c 100644
--- a/saleor/core/management/commands/populatedb.py
+++ b/saleor/core/management/commands/populatedb.py
@@ -55,8 +55,7 @@ class Command(BaseCommand):
create_images = not options['withoutimages']
for msg in create_shipping_zones():
self.stdout.write(msg)
- create_products_by_schema(
- self.placeholders_dir, create_images, stdout=self.stdout)
+ create_products_by_schema(self.placeholders_dir, create_images)
self.stdout.write('Created products')
for msg in create_product_sales(5):
self.stdout.write(msg)
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 7fa417e2dd..68eed28f6a 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -195,8 +195,9 @@ def create_product_variants(variants_data):
ProductVariant.objects.update_or_create(pk=pk, defaults=defaults)
-def create_products_by_schema(placeholder_dir, create_images, stdout=None):
- with open('saleor/static/db.json') as f:
+def create_products_by_schema(placeholder_dir, create_images):
+ path = os.path.join(settings.PROJECT_ROOT, 'saleor', 'static', 'db.json')
+ with open(path) as f:
db_items = json.load(f, object_hook=object_hook)
types = defaultdict(list)
# Sort db objects by its model
diff --git a/tests/test_core.py b/tests/test_core.py
index f77c077615..da524f6dc3 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -121,7 +121,7 @@ def test_create_fake_order(db, monkeypatch, product_image):
pass
for _ in random_data.create_users(3):
pass
- random_data.create_products_by_schema('/', 10, False)
+ random_data.create_products_by_schema('/', 10)
how_many = 5
for _ in random_data.create_orders(how_many):
pass