diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c3d4d7e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + branches: + - 'main' + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r dev-requirements.txt + - name: Build and release + run: | + python -m build + twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} dist/* diff --git a/django_querysets_single_query_fetch/service.py b/django_querysets_single_query_fetch/service.py index 5368b03..e908a98 100644 --- a/django_querysets_single_query_fetch/service.py +++ b/django_querysets_single_query_fetch/service.py @@ -190,13 +190,11 @@ def _get_django_sql_for_queryset(self, queryset: QuerySet) -> str: return "" for param in params: - if ( - isinstance(param, str) - or isinstance(param, UUID) - or isinstance(param, datetime.datetime) - ): + if isinstance(param, str): # this is to handle special char handling - param = QuotedString(f"{param}").getquoted().decode("utf-8") + param = QuotedString(param).getquoted().decode("utf-8") + elif isinstance(param, UUID) or isinstance(param, datetime.datetime): + param = f"'{param}'" elif isinstance(param, int) or isinstance(param, float): # type which can be passed as is pass @@ -319,9 +317,9 @@ def _get_instances_from_results_for_model_iterable( obj_fields_cache = {} # because of json_agg some field level parsing/handling broke, patch it for prefetched objects for prefetched_obj_name, prefetched_obj in obj._state.fields_cache.items(): - obj_fields_cache[ - prefetched_obj_name - ] = self._transform_object_to_handle_json_agg(obj=prefetched_obj) + obj_fields_cache[prefetched_obj_name] = ( + self._transform_object_to_handle_json_agg(obj=prefetched_obj) + ) obj._state.fields_cache = obj_fields_cache instances.append(obj) return instances diff --git a/manage.py b/manage.py index 8bd034f..699bc9d 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,6 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" + import os import sys diff --git a/testapp/tests/test_behaviour_for_postgres.py b/testapp/tests/test_behaviour_for_postgres.py index 2130d08..a42e6f6 100644 --- a/testapp/tests/test_behaviour_for_postgres.py +++ b/testapp/tests/test_behaviour_for_postgres.py @@ -170,14 +170,25 @@ def test_fetch_count(self): def test_quotes_inside_the_string_in_select_query_will_work(self): name = "Ap's" - product_with_name_contain_quotes = baker.make( + product = baker.make( StoreProduct, store=self.store, category=self.category, selling_price=100.33, name=name, ) - product = QuerysetsSingleQueryFetch( + products = QuerysetsSingleQueryFetch( querysets=[StoreProduct.objects.filter(name=name)] - ).execute() - self.assertEqual(product_with_name_contain_quotes.id, product[0][0].id) + ).execute()[0] + self.assertEqual(product.id, products[0].id) + + def test_search_by_datetime_will_work(self): + stores = QuerysetsSingleQueryFetch( + querysets=[ + OnlineStore.objects.filter( + created_at=self.store.created_at, id=self.store.id + ) + ] + ).execute()[0] + self.assertEqual(len(stores), 1) + self.assertEqual(self.store.id, stores[0].id) diff --git a/testproject/urls.py b/testproject/urls.py index 5d59ea0..6b582c7 100644 --- a/testproject/urls.py +++ b/testproject/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.contrib import admin from django.urls import path