Wednesday, October 16, 2024

Re: ORM Bug from extending the `Query` class

This won't solve your problem but tangentially I've made a custom field lookup for `relatedfield__neq=objectToExclude`


On Tue, Oct 15, 2024 at 3:59 PM Ben Pearman <ben.pearman@koordinates.com> wrote:
Hi all,

We wrote some custom logic that extended the `Query` class. It worked fine in 3.2 but not for 4.1, and it started producing invalid SQL. We filed a ticket (https://code.djangoproject.com/ticket/35836) but haven't made any progress since `Query` is an undocumented API.

Our use case is an automatic site filter - objects belonging to different customer sites are automatically filtered to the current site, so each queryset doesn't have to be explicitly filtered. We did this at the Query level rather than filtering the default manager's `get_queryset`. This has the useful effect that our DRF views can define a queryset attribute on their class definition (where there isn't a 'current' site) and the query will be filtered when it is actually executed (in a request context on a particular site)

How should we change our usage of `Query` to fix the bug? Below is the contents of the ticket, including a reproduction.

Thanks,
Ben Pearman

___

We have observed a bug in the ORM where invalid SQL can be produced.

A reproduction can be seen here:
https://github.com/benpearman/django-orm-bug
And specifically:
https://github.com/benpearman/django-orm-bug/blob/master/demo/models.py

It is caused with the following steps:

  1. Subclassing `django.db.models.sql.Query` and using it in a Queryset mixin
  2. Creating a queryset with an `exclude()` expression which includes a subquery. EG `Classroom.objects.exclude(student_set__id=student_A.id)`
  3. Then before calling `super().get_compiler` from our subclassed Query:
    • Clone the query
    • Adding a simple expression via `cloned_query.add_q` eg `cloned_query.add_q(Q(school_id=1))`
    • Passing the cloned query into `super().get_compiler`
  4. Then evaluate the queryset, which produces invalid SQL and raises `django.db.utils.OperationalError`

Note the issue happens when `get_compiler` is invoked for the subquery, not on the main query itself.

This was working for us in Django 3.2, but not for Django 4.1

git bisect shows the breakage was introduced by this commit:
https://github.com/django/django/commit/14c8504a37afad96ab93cf82f47b13bcc4d00621

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/af1c619d-eaed-4ad8-896f-849d86f9a674n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALmEK1tZjb%2BTYbgTyw7HR86uCKyKakkt0p31g%2BZUtTNdECyBBw%40mail.gmail.com.

Tuesday, October 15, 2024

ORM Bug from extending the `Query` class

Hi all,

We wrote some custom logic that extended the `Query` class. It worked fine in 3.2 but not for 4.1, and it started producing invalid SQL. We filed a ticket (https://code.djangoproject.com/ticket/35836) but haven't made any progress since `Query` is an undocumented API.

Our use case is an automatic site filter - objects belonging to different customer sites are automatically filtered to the current site, so each queryset doesn't have to be explicitly filtered. We did this at the Query level rather than filtering the default manager's `get_queryset`. This has the useful effect that our DRF views can define a queryset attribute on their class definition (where there isn't a 'current' site) and the query will be filtered when it is actually executed (in a request context on a particular site)

How should we change our usage of `Query` to fix the bug? Below is the contents of the ticket, including a reproduction.

Thanks,
Ben Pearman

___

We have observed a bug in the ORM where invalid SQL can be produced.

A reproduction can be seen here:
https://github.com/benpearman/django-orm-bug
And specifically:
https://github.com/benpearman/django-orm-bug/blob/master/demo/models.py

It is caused with the following steps:

  1. Subclassing `django.db.models.sql.Query` and using it in a Queryset mixin
  2. Creating a queryset with an `exclude()` expression which includes a subquery. EG `Classroom.objects.exclude(student_set__id=student_A.id)`
  3. Then before calling `super().get_compiler` from our subclassed Query:
    • Clone the query
    • Adding a simple expression via `cloned_query.add_q` eg `cloned_query.add_q(Q(school_id=1))`
    • Passing the cloned query into `super().get_compiler`
  4. Then evaluate the queryset, which produces invalid SQL and raises `django.db.utils.OperationalError`

Note the issue happens when `get_compiler` is invoked for the subquery, not on the main query itself.

This was working for us in Django 3.2, but not for Django 4.1

git bisect shows the breakage was introduced by this commit:
https://github.com/django/django/commit/14c8504a37afad96ab93cf82f47b13bcc4d00621

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/af1c619d-eaed-4ad8-896f-849d86f9a674n%40googlegroups.com.

Monday, October 14, 2024

Re: oRe: Error in project

Hi ,
did yout sorted this error 

On Mon, 14 Oct 2024 at 16:14, Kashaf Online <kashafonline4@gmail.com> wrote:
okay I got the point thank you so uch

On Sunday, October 13, 2024 at 5:19:05 PM UTC-7 Sri Santhosh wrote:

Shows there is some issue in the settings.py


On Fri, Oct 11, 2024, 1:49 AM Kashaf Online <kashaf...@gmail.com> wrote:
Greetings everyone!

I just want to express my trouble . I want to create a Chatbot with the help of python an django. My project contains different errors please help me to resolve this. Screenshot (18).png

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d30d897-0969-4c3a-9ffe-18283c1ccc27n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2cc4560-2453-4808-ba9f-ff9d725ea85bn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADJMz_%3D2Bdyhd3s4bEWO%3D5-t01tfAYCPUxzg%2Bh8NTx5%2BQEzqLw%40mail.gmail.com.

oRe: Error in project

okay I got the point thank you so uch

On Sunday, October 13, 2024 at 5:19:05 PM UTC-7 Sri Santhosh wrote:

Shows there is some issue in the settings.py


On Fri, Oct 11, 2024, 1:49 AM Kashaf Online <kashaf...@gmail.com> wrote:
Greetings everyone!

I just want to express my trouble . I want to create a Chatbot with the help of python an django. My project contains different errors please help me to resolve this. Screenshot (18).png

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d30d897-0969-4c3a-9ffe-18283c1ccc27n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2cc4560-2453-4808-ba9f-ff9d725ea85bn%40googlegroups.com.

Sunday, October 13, 2024

Re: MicroService related issue

Hi 

You can email me so we can schedule a call to review it.

Regards

AJAYI Sunday 
(+234) 806 771 5394



On Mon, Oct 14, 2024 at 1:18 AM Konstantinos Dimitropoulos <cdemetropoulos@gmail.com> wrote:
Hello, why don't you create a project with two apps? Authenticate and repaire

Le ven. 11 oct. 2024, 11:01, shiva singh <shivasingh604@gmail.com> a écrit :
Hello
  I am currently working on a microservices project using Django and have encountered an issue.  
 i am facing issue when create microservice project using django i am created 2 difrent django project in one common folder and one project name is authentication and second project name is repairmodule and when i access authentication project's model class in repairmodule models class and when i run makemigrations i am getting this error:
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\BSInfosys\RepairAnything\repairmodule\repair\models.py", line 2, in <module>
    from authentication.authenticate.models import User, RepairManProfile
ModuleNotFoundError: No module named 'authentication'
this is my directory Structure:
RepairAnything/
├── authentication/
│   ├── manage.py
│   ├── authentication/
│   │   ├── __init__.py
│   │   ├── asgi.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   ├── wsgi.py
│   │   └── __pycache__/
│   └── authenticate/
│       ├── __init__.py
│       ├── admin.py
│       ├── apps.py
│       ├── migrations/
│       │   └── __init__.py
│       ├── models.py
│       ├── serializers.py
│       ├── tests.py
│       ├── urls.py
│       └── views.py
├── env/                   # Your virtual environment
├── repairmodule/
│   ├── manage.py
│   ├── repair/
│   │   ├── __init__.py
│   │   └── models.py
│   └── repairmodule/
│       ├── __init__.py
│       ├── asgi.py
│       ├── settings.py
│       ├── urls.py
│       ├── wsgi.py
│       └── __pycache__/
├── db.sqlite3            # Database file
├── .env                  # Environment variables file
├── .gitignore            # Git ignore file
└── README.md             # Project README file

I would appreciate your guidance on how to resolve this issue. If you need any additional information, please let me know.

Thank you for your time and assistance!

Best regards,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEsRHMWn1PSmBcD%3Db6jLqYwnCD-FsVtgvKXuAe8kybRo%2BmEQDg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOKiqZkMEKqEUad4gg4CRtDYiHT-8%3Dr-x1Ya4VxmY95tj3hGPA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKYSAw0S1LN3EGH8G68mMphLiXvsQSMZScSf6t6iR3fMX8hJkA%40mail.gmail.com.

Help for deployment with ArgoCD, kubernetes and gitlab CI/CD

Hi everyone,

I hope everything is going well for you.

Someone here can help me to deploy on my VPS server by using Argo-CD, kubernetes and Gitlab CI/CD ?

Best Regards.

--
theodoros17@python-developer

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKiMjQGFRBN%3DkfyBFC_ZqxmS9e_1y2Tfsy%3DiGTmbV-1zr8RppA%40mail.gmail.com.

Saturday, October 12, 2024

Re: jwt authentication in ninja without django user

Hi Krishnakant,

If you wanna use Django Ninja's Auth, then use it properly: Authentication - Django Ninja (django-ninja.dev)

And if you insist on logging in with JWT, please use django-ninja-jwt. django-ninja-jwt · PyPI

On Fri, 11 Oct 2024 at 23:28, Krishnakant Mane <kkproghub@gmail.com> wrote:

Hello.

This seems very complex to me.

I have previously used other Python and non-Python frameworks and one thing I always did is to create my own user table and respective model.

I wish to do the same thing in django with ninja.

I also find the jwt authentication articles/ blogs online very complex.

Can some one guide me to a simple explanation?

My requirement is very simple.

I have an accounts table with all user data including username and password.

The user creates this during registration, I don't want to use the django user model.

Now every time the user logs in, I wish to generate the token and with every request I need to authentication.

I know that in the router.get or router.post decorator I will have to inject the authentication function.

But no tutorial gives a clear indication of where to create this class and no simple code to just authenticate and go ahead.

I am trying to use simplejwt from rest_framework.

If this is not the correct way please guide.

Regards.

--
Krishnakant Mane
Software Architecture Design & Implementation Specialist

Mobile:
+91 8424039903
https://www.linkedin.com/in/krishnakant-r-mane/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9326d678-fefd-4176-8a61-d24c86c6bc1c%40gmail.com.


--
Abdul Qoyyuum Bin Haji Abdul Kadir
Nickname: Q

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANVqoJ8KGfcdkzmx_q4V%3D-DiWtNsq-aHmw19C84BocuOA60qoA%40mail.gmail.com.