Skip to content

Refs #28643 -- Added Repeat database function. #9808

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

Merged
merged 1 commit into from
Apr 3, 2018

Conversation

felixxm
Copy link
Member

@felixxm felixxm commented Mar 21, 2018

@felixxm felixxm force-pushed the 28643-repeat branch 2 times, most recently from 37014cb to 8653ab3 Compare March 21, 2018 18:12
@felixxm
Copy link
Member Author

felixxm commented Mar 21, 2018

Failures on MySQL are not related with this PR, it returns wrong results also for other functions, e.g. LPad('name', Length('alias')). I'll investigate 🕵️‍♂️ .

@felixxm
Copy link
Member Author

felixxm commented Mar 21, 2018

It turns out that mysqlclient returns bytes instead of strings in some cases (see similar issue), therefore if I use TextField (with the explicit converter convert_textfield_value) everything works as expected.

@timgraham
Copy link
Member

Looks good, pending the MySQL issue.

Copy link
Member

@ngnpope ngnpope left a comment

Choose a reason for hiding this comment

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

LGTM. Just the one suggestion.

@@ -170,6 +170,7 @@ def get_new_connection(self, conn_params):
conn.create_function("django_format_dtdelta", 3, _sqlite_format_dtdelta)
conn.create_function("django_power", 2, _sqlite_power)
conn.create_function('LPAD', 3, _sqlite_lpad)
conn.create_function('REPEAT', 2, _sqlite_repeat)
Copy link
Member

Choose a reason for hiding this comment

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

I'd make this a lambda or use operator.mul.

@felixxm
Copy link
Member Author

felixxm commented Mar 22, 2018

I added the separate ticket 29251 for the MySQL issue.

authors = Author.objects.annotate(repeated_text=function)
self.assertQuerysetEqual(authors, [repeated_text], lambda a: a.repeated_text, ordered=False)

def test_repeat_negative_number(self):
Copy link
Member

Choose a reason for hiding this comment

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

chop "_repeat"



class RepeatTests(TestCase):
def test_repeat(self):
Copy link
Member

Choose a reason for hiding this comment

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

test_basic

Thanks Tim Graham and Nick Pope for reviews.
@felixxm felixxm merged commit 55cc269 into django:master Apr 3, 2018
@felixxm
Copy link
Member Author

felixxm commented Apr 3, 2018

@timgraham Thanks for the review.

@felixxm felixxm deleted the 28643-repeat branch April 3, 2018 17:36
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