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

Added support for NATURAL_SORT_KEY with MariaDB #1018

Closed
wants to merge 5 commits into from

Conversation

aduuna
Copy link

@aduuna aduuna commented Jun 23, 2023

Fixes #975

This PR adds support for MariaDB's NATURAL_SORT_KEY. It has been implemented as a database function.

Alphabet.objects.order_by(NaturalSortKey("d"))

Copy link
Owner

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

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

I'm not interested in adding database functions that take so little effort to implement in your own project. The functions we have in the package have more restricted types, which helps users call them correctly. Could you do the same here?

Also every pull request needs documentation and a changelog note.

connection: BaseDatabaseWrapper,
**extra_context,
) -> tuple[str, tuple[Any, ...]]:
if connection.vendor == "mysql" and not connection.mysql_is_mariadb:
Copy link
Owner

Choose a reason for hiding this comment

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

These database version checks are not worth it. In the successful path, all of this checking is time wasted (creating a Version is not free!). In the incredibly rare failure path, they’re not really providing more information than the database’s own error (“no such function”) would provide.

This is why none of the other functions have such checks.

Copy link
Author

@aduuna aduuna Jun 24, 2023

Choose a reason for hiding this comment

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

Thank you for your feedback. I understand your concerns about the database version checks in the code. But my reasoning was that While these checks can introduce overhead and may not always provide significant additional information, they serve as a preventive measure to catch potential issues early on.

I will look through the open issue pool on the Django projects to find a first-time-contributor friendly to contribute to.

Thanks Adam 👍

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I'm all for preventative checks, but their cost has to be balanced against the probability of making a given mistake.

@adamchainz
Copy link
Owner

I’m sorry I still don’t think we are adding much of utility above the original two line function definition. Simply restricting to a single expression isn’t reason enough to add a custom class and maintain it forever. Thanks.

@adamchainz adamchainz closed this Jun 24, 2023
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.

Add support for natural sorting with MariaDB 10.7+ NATURAL_SORT_KEY
2 participants