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

fix: remove unused 'charset' in generate schema encoders #1817

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

nglehuy
Copy link

@nglehuy nglehuy commented Dec 17, 2024

Remove unused 'charset' in generate schema encoders

Description

  • remove unused 'charset' in generate schema encoders
  • update element_type in ArrayField of postgres to be uppercase

Motivation and Context

Error when using get_schema_sql on ArrayField with default value

self = <tortoise.backends.asyncpg.schema_generator.AsyncpgSchemaGenerator object at 0x106f28440>, default = [0, 0, 0, 0]

    def _escape_default_value(self, default: Any):
        if isinstance(default, bool):
            return default
>       return encoders.get(type(default))(default)  # type: ignore
E       TypeError: escape_sequence() missing 1 required positional argument: 'charset'

Encoders functions should accept the same number of arguments

How Has This Been Tested?

Update tests/schema/models_postgres_index.py, tests/schema/test_generate_schema.py and run make test

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Contributor

@henadzit henadzit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! I added a single comment.

@@ -19,6 +19,7 @@ class Index(Model):
sp_gist = fields.CharField(max_length=200)
hash = fields.CharField(max_length=200)
partial = fields.CharField(max_length=200)
array = ArrayField(element_type="text", default=["a", "b", "c"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Index model is used for testing indexes specifically and there is no index on array in this case. It would be better to use another model for testing arrays.

It might make sense to add a new test or find a more suitable one.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 12378120829

Details

  • 7 of 9 (77.78%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 90.647%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/converters.py 6 8 75.0%
Totals Coverage Status
Change from base Build 12342471369: 0.2%
Covered Lines: 6322
Relevant Lines: 6868

💛 - Coveralls

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

Successfully merging this pull request may close these issues.

3 participants