Skip to content

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

Removed invalid static methods and fix some missing optimizations

NyanKiyoshidd194ca6265a
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index 283ef78c33..d6ab5549bf 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -146,7 +146,7 @@ class VoucherDelete(ModelDeleteMutation):
class VoucherBaseCatalogueMutation(BaseDiscountCatalogueMutation):
voucher = graphene.Field(
Voucher,
- description=('Voucher of which catalogue IDs will be modified.'))
+ description='Voucher of which catalogue IDs will be modified.')
class Arguments:
id = graphene.ID(required=True, description='ID of a voucher.')
@@ -258,13 +258,13 @@ class SaleDelete(ModelDeleteMutation):
class SaleBaseCatalogueMutation(BaseDiscountCatalogueMutation):
sale = graphene.Field(
- Sale, description=('Sale of which catalogue IDs will be modified.'))
+ Sale, description='Sale of which catalogue IDs will be modified.')
class Arguments:
id = graphene.ID(required=True, description='ID of a sale.')
input = CatalogueInput(
required=True,
- description=('Fields required to modify catalogue IDs of sale.'))
+ description='Fields required to modify catalogue IDs of sale.')
class Meta:
abstract = True
diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.py
index c94606c021..51e2ca7a29 100644
--- a/saleor/graphql/middleware.py
+++ b/saleor/graphql/middleware.py
@@ -14,7 +14,7 @@ def jwt_middleware(get_response):
"""
# Disable warnings for django-graphene-jwt
graphene_settings.MIDDLEWARE.append(JSONWebTokenMiddleware)
- jwt_middleware = JSONWebTokenMiddleware(get_response=get_response)
+ jwt_middleware_inst = JSONWebTokenMiddleware(get_response=get_response)
graphene_settings.MIDDLEWARE.remove(JSONWebTokenMiddleware)
def middleware(request):
@@ -24,7 +24,7 @@ def jwt_middleware(get_response):
request.user = AnonymousUser()
# authenticate using JWT middleware
- jwt_middleware.process_request(request)
+ jwt_middleware_inst.process_request(request)
return get_response(request)
return middleware
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 08e507352c..e022cf0e3e 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -45,30 +45,30 @@ class OrderEvent(CountableDjangoObjectType):
interfaces = [relay.Node]
only_fields = ['id']
- def resolve_email(self, info):
+ def resolve_email(self, _info):
return self.parameters.get('email', None)
- def resolve_email_type(self, info):
+ def resolve_email_type(self, _info):
return self.parameters.get('email_type', None)
- def resolve_amount(self, info):
+ def resolve_amount(self, _info):
amount = self.parameters.get('amount', None)
return float(amount) if amount else None
- def resolve_quantity(self, info):
+ def resolve_quantity(self, _info):
quantity = self.parameters.get('quantity', None)
return int(quantity) if quantity else None
- def resolve_message(self, info):
+ def resolve_message(self, _info):
return self.parameters.get('message', None)
- def resolve_composed_id(self, info):
+ def resolve_composed_id(self, _info):
return self.parameters.get('composed_id', None)
- def resolve_oversold_items(self, info):
+ def resolve_oversold_items(self, _info):
return self.parameters.get('oversold_items', None)
- def resolve_order_number(self, info):
+ def resolve_order_number(self, _info):
return self.order_id
@@ -82,7 +82,7 @@ class FulfillmentLine(CountableDjangoObjectType):
only_fields = ['id', 'quantity']
@gql_optimizer.resolver_hints(prefetch_related='order_line')
- def resolve_order_line(self, info):
+ def resolve_order_line(self, _info):
return self.order_line
@@ -103,10 +103,10 @@ class Fulfillment(CountableDjangoObjectType):
'fulfillment_order', 'id', 'shipping_date', 'status',
'tracking_number']
- def resolve_lines(self, info):
+ def resolve_lines(self, _info):
return self.lines.all()
- def resolve_status_display(self, info):
+ def resolve_status_display(self, _info):
return self.get_status_display()
@@ -160,8 +160,7 @@ class OrderLine(CountableDjangoObjectType):
alt = image.alt if image else None
return Image(alt=alt, url=info.context.build_absolute_uri(url))
- @staticmethod
- def resolve_unit_price(self, info):
+ def resolve_unit_price(self, _info):
return self.unit_price
@@ -235,8 +234,7 @@ class Order(CountableDjangoObjectType):
'shipping_price', 'status', 'token', 'tracking_client_id',
'translated_discount_name', 'user', 'voucher', 'weight']
- @staticmethod
- def resolve_shipping_price(self, info):
+ def resolve_shipping_price(self, _info):
return self.shipping_price
@gql_optimizer.resolver_hints(prefetch_related='payments__transactions')
@@ -253,31 +251,25 @@ class Order(CountableDjangoObjectType):
actions.append(OrderAction.VOID)
return actions
- @staticmethod
- def resolve_subtotal(self, info):
+ def resolve_subtotal(self, _info):
return self.get_subtotal()
- @staticmethod
- def resolve_total(self, info):
+ def resolve_total(self, _info):
return self.total
- @staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments__transactions')
- def resolve_total_authorized(self, info):
+ def resolve_total_authorized(self, _info):
# FIXME adjust to multiple payments in the future
return self.total_authorized
- @staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments')
- def resolve_total_captured(self, info):
+ def resolve_total_captured(self, _info):
# FIXME adjust to multiple payments in the future
return self.total_captured
- @staticmethod
- def resolve_total_balance(self, info):
+ def resolve_total_balance(self, _info):
return self.total_balance
- @staticmethod
def resolve_fulfillments(self, info):
user = info.context.user
if user.is_staff:
@@ -286,61 +278,52 @@ class Order(CountableDjangoObjectType):
qs = self.fulfillments.exclude(status=FulfillmentStatus.CANCELED)
return qs.order_by('pk')
- @staticmethod
- def resolve_lines(self, info):
+ def resolve_lines(self, _info):
return self.lines.all().order_by('pk')
- @staticmethod
- def resolve_events(self, info):
+ def resolve_events(self, _info):
return self.events.all().order_by('pk')
- @staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments')
- def resolve_is_paid(self, info):
+ def resolve_is_paid(self, _info):
return self.is_fully_paid()
- @staticmethod
- def resolve_number(self, info):
+ def resolve_number(self, _info):
return str(self.pk)
- @staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments')
- def resolve_payment_status(self, info):
+ def resolve_payment_status(self, _info):
return self.get_payment_status()
- @staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments')
- def resolve_payment_status_display(self, info):
+ def resolve_payment_status_display(self, _info):
return self.get_payment_status_display()
- @staticmethod
- def resolve_payments(self, info):
+ def resolve_payments(self, _info):
return self.payments.all()
- @staticmethod
- def resolve_status_display(self, info):
+ def resolve_status_display(self, _info):
return self.get_status_display()
@staticmethod
- def resolve_can_finalize(self, info):
+ def resolve_can_finalize(self, _info):
try:
validate_draft_order(self)
except ValidationError:
return False
return True
- @staticmethod
- def resolve_user_email(self, info):
+ @gql_optimizer.resolver_hints(select_related='user')
+ def resolve_user_email(self, _info):
if self.user_email:
return self.user_email
if self.user_id:
return self.user.email
return None
- @staticmethod
def resolve_available_shipping_methods(self, info):
return applicable_shipping_methods(
self, self.get_subtotal().gross.amount)
- def resolve_is_shipping_required(self, info):
+ def resolve_is_shipping_required(self, _info):
return self.is_shipping_required()
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 5fd91c6076..84f7f43505 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -466,12 +466,6 @@ class ProductType(CountableDjangoObjectType):
PrefetchingConnectionField(
Product, description='List of products of this type.'),
prefetch_related=prefetch_products)
- product_attributes = gql_optimizer.field(
- PrefetchingConnectionField(Attribute),
- model_field='product_attributes')
- variant_attributes = gql_optimizer.field(
- PrefetchingConnectionField(Attribute),
- model_field='variant_attributes')
tax_rate = TaxRateType(description='A type of tax rate.')
variant_attributes = graphene.List(
Attribute, description='Variant attributes of that product type.')
@@ -487,9 +481,11 @@ class ProductType(CountableDjangoObjectType):
'has_variants', 'id', 'is_digital', 'is_shipping_required', 'name',
'weight']
+ @gql_optimizer.resolver_hints(prefetch_related='product_attributes')
def resolve_product_attributes(self, info, **kwargs):
return self.product_attributes.all()
+ @gql_optimizer.resolver_hints(prefetch_related='variant_attributes')
def resolve_variant_attributes(self, info, **kwargs):
return self.variant_attributes.all()
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 6116cc35fb..af5815cdf1 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -1496,7 +1496,7 @@ def test_product_type_update_changes_variant_name(
'variantAttributes': variant_attributes_ids}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_products])
- content = get_graphql_content(response)
+ get_graphql_content(response)
variant_attributes = set(variant_attributes)
variant_attributes_ids = [attr.pk for attr in variant_attributes]
mock_update_variants_names.assert_called_once_with(