Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: wrong docs generated for sorters with different names, but the same values #10968

Open
zedzior opened this issue Oct 18, 2022 · 0 comments
Labels

Comments

@zedzior
Copy link
Member

zedzior commented Oct 18, 2022

What are you trying to achieve?

https://saleorcommerce.slack.com/archives/C039MGJDWU8/p1665750963551539

The thing is python built-in Enum returns wrong name if two members, with different names, have the same value.
Example:

class PageSortField(graphene.Enum):
  TITLE = ["title", "slug"]
  SLUG = ["slug"]
  VISIBILITY = ["is_published", "title", "slug"]
  CREATION_DATE = ["created_at", "title", "slug"]
  PUBLICATION_DATE = ["published_at", "title", "slug"]
  PUBLISHED_AT = ["published_at", "title", "slug"]

  @property
  def description(self):
    if self.name in PageSortField.__enum__._member_names_:
      sort_name = self.name.lower().replace("_", " ")
      description = f"Sort pages by {sort_name}."
      if self.name == "PUBLICATION_DATE":
        description += DEPRECATED_IN_3X_INPUT
      return description
    raise ValueError("Unsupported enum value: %s" % self.value)

Note, that PUBLICATION_DATE and PUBLISHED_AT have the same values. It results descriptions in graphql.schema and playground have DEPRECATED_IN_3X_INPUT info. We want to add the info only for PUBLICATION_DATE and not for PUBLISHED_AT.

image

Steps to reproduce the problem

  1. Find class PageSortField(graphene.Enum)
  2. Add two new sorters, with different name and same value
  3. For one of them, apply some description
  4. Run npm run build-schema
  5. Check, that the description is applied to both sorters

What did you expect to happen?

The description is applied to single sorter

Logs

No response

Environment

Saleor version: 3.7
OS and version: macOS Big Sur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant