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

Parametrize UPDATE, DELETE and bulk operations #1785

Merged

Conversation

henadzit
Copy link
Contributor

@henadzit henadzit commented Nov 24, 2024

Description

It's a follow up to #1777.

  • Parametrizes UPDATE, DELETE and bulk update and create operations

We will also need to parametrize fetching of m2m fields, prefetching, etc. but these are not posing security risks. I'll do them as a separate PR.

Motivation and Context

Parameterized queries are crucial for preventing SQL injection attacks and but also can improve performance of database operations.

Related ticket #81
v1.0.0 target #19

How Has This Been Tested?

  • Tests
  • Tested with a web app localy

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.

@@ -76,6 +77,11 @@ def to_db_time(
return None


# Converts Decimal to string for sqlite in cases where it's hard to know the
# related field, e.g. in raw queries, math or annotations.
sqlite3.register_adapter(Decimal, str)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coveralls
Copy link

coveralls commented Nov 24, 2024

Pull Request Test Coverage Report for Build 12116346174

Details

  • 34 of 35 (97.14%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 90.39%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/queryset.py 28 29 96.55%
Totals Coverage Status
Change from base Build 12110183517: 0.1%
Covered Lines: 6312
Relevant Lines: 6877

💛 - Coveralls

@henadzit henadzit force-pushed the feat/parametrize-other-queries branch from 843cecc to fa7c374 Compare November 28, 2024 14:14
0.22.1
------
Fixed
^^^^^
- Fix unable to use ManyToManyField if OneToOneField passed as Primary Key (#1783)
- Fix sorting by Term (e.g. RawSQL) (#1788)

Changed
^^^^^^^
- Parametrizes SELECT queries including `.count()`, `.exists()`, `.values()`, `.values_list()` (#1777)
Copy link
Contributor Author

@henadzit henadzit Nov 28, 2024

Choose a reason for hiding this comment

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

We released this with 0.22.1 too 🙃 I'll be updating CHANGELOG from now on in my PR to avoid missing things like that.

@henadzit
Copy link
Contributor Author

henadzit commented Dec 1, 2024

@abondar can you have a look at this? Thanks!

abondar
abondar previously approved these changes Dec 2, 2024
@waketzheng waketzheng merged commit e762837 into tortoise:develop Dec 2, 2024
7 checks passed
@henadzit henadzit mentioned this pull request Dec 8, 2024
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.

4 participants