Re: Import [python django module] could not be resolved from source Pylance (reportMissingModuleSource) -- even though Django is installed in my venv

2023-04-28 Thread ALBERT ASHABA AHEEBWA
This is a wild suggestion, but as someone here mentioned, your vscode might
be pointing to the wrong interpreter.

Check at the bottom bar of your vscode with a .py file open. Next to
{}python you should see what environment you are using.

eg. 3.11.3 64-bit or 3.11.3('.venv':venv)

The latter is what you are looking for. If it's not, click on whatever is
there and on popup, select the appropriate.



Best Regards,

Albert Ashaba Aheebwa
+256 781 435857

On Thu, 27 Apr 2023, 23:48 Michael Starr, 
wrote:

> I did pip install django on my venv, which is activated, and it reported
> already installed. But the following modules are reporting the error in the
> subject line:
> django.db
> models
> django.utils.crypto
> django.urls
> django.contrib
> admin
> django.shortcuts
> django.views.generic
>
> I don't know what's wrong. My server runs in development mode (not in
> production yet), but there havev been some bugs that are hard to imagine
> are caused by this, but still (images not loading, CSS not loading).
>
> Thanks.
>
> Michael
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f7977c43-90ef-4423-bb36-07c550bfda52n%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAQecPex9WvQ%3D4Yq3UKQPiY9U8otmNvRwpwTkfekzcsZeV8xNg%40mail.gmail.com.


Re: Django ORM: move filter after annotate subquery

2023-04-28 Thread Aivan Fouren


I found a way to achieve the results I want: applying a filter, `
date_created__lte` in this example, outside of annotated query:
sub = Model.objects.all() \
  .annotate(ord=Window(
expression=RowNumber(),
partition_by=F('related_id'),
order_by=[F('date_created').desc()] ) ) \
   .filter(ord=1)

result = Model.objects.all() \
  .filter(id__in=sub.values_list('id')) \
  .filter(date_created__lte=some_datetime)

However, this is not a code I want, it's bad from performance point of view 
due to HASH JOIN. Of course, I can write a raw SQL query, parse values by 
Django ORM, but this looks too heavy for a simple nested subquery. So, a 
better version is appreciated 

On Friday, April 28, 2023 at 4:52:16 PM UTC+3 Aivan Fouren wrote:

> This Django ORM statement:
> Model.objects.all() \
>   .annotate( ord=Window(
>  expression=RowNumber(), 
>  partition_by=F('related_id'),
>  order_by=[F("date_created").desc()] 
>   ) \
>   .filter(ord=1) \
>   .filter(date_created__lte=some_datetime)
>
> Leads to the following SQL query:
> SELECT *
> FROM (
>   SELECT
> id, related_id, values, date_created ROW_NUMBER() OVER (
>   PARTITION BY related_id ORDER BY date_created DESC
> ) AS ord
>   FROM model_table
>   WHERE date_created <= 2022-02-24 00:00:00+00:00
> )
> WHERE ord = 1;
>
> As you can see, the `date_created__lte` filter gets applied on the inner 
> query. Is it possible to control statement location preciser and move the 
> filter outside, like `ord`?
>
>
> I also asked this on StackOverflow 
> , got an advice to use 
> `Subquery` object, but as far as I know this class is used for filtering or 
> annotated selecting values (SQL SELECT, WHERE), but I need a subquery to 
> use inside FROM statement, so that I can postprocess calculated results.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9afee8b7-ccb3-4143-8fc5-af05626c6e8en%40googlegroups.com.


Django ORM: move filter after annotate subquery

2023-04-28 Thread Aivan Fouren


This Django ORM statement:
Model.objects.all() \
  .annotate( ord=Window(
 expression=RowNumber(), 
 partition_by=F('related_id'),
 order_by=[F("date_created").desc()] 
  ) \
  .filter(ord=1) \
  .filter(date_created__lte=some_datetime)

Leads to the following SQL query:
SELECT *
FROM (
  SELECT
id, related_id, values, date_created ROW_NUMBER() OVER (
  PARTITION BY related_id ORDER BY date_created DESC
) AS ord
  FROM model_table
  WHERE date_created <= 2022-02-24 00:00:00+00:00
)
WHERE ord = 1;

As you can see, the `date_created__lte` filter gets applied on the inner 
query. Is it possible to control statement location preciser and move the 
filter outside, like `ord`?


I also asked this on StackOverflow 
, got an advice to use 
`Subquery` object, but as far as I know this class is used for filtering or 
annotated selecting values (SQL SELECT, WHERE), but I need a subquery to 
use inside FROM statement, so that I can postprocess calculated results.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/74df5810-9bb7-4926-9904-73b86f06f174n%40googlegroups.com.


Re: Import [python django module] could not be resolved from source Pylance (reportMissingModuleSource) -- even though Django is installed in my venv

2023-04-28 Thread Emalexogah Ogah
If you felt the problem was vs code, I have a suggestion. Try it out and if
it works, get back to me.
Open your comman prompt terminal and input
Python -m venv venv (press enter)
Venv/static/activate (press enter)
Then install django again

On Fri, Apr 28, 2023, 3:27 AM Michael Starr 
wrote:

> Thank you for the replies. I am overwhelmed right now but will check back
> on them later.
>
> I think you two are right that it's the IDE. It's VSCode (I don't know
> what version). I was just suspicious b/c there were some strange bugs in my
> django project. I won't worry about it. If it annoys me I'll redirect the
> pointers.
>
> Michael
>
> On Thursday, April 27, 2023 at 3:27:31 PM UTC-7 Khaleel Ahmed H. M.
> Shariff wrote:
>
>> Hi Michael
>>
>> May Peace, Blessings & Mercy of Almighty God be on you!
>>
>> do you know how to modify the sys.path to add the directory where the
>> listed modules are installed?
>>
>> On Linux/UNIX
>> Execute the find command to locate the directory where the modules are
>> installed and include the same in the path
>>
>> On windows
>> Execute the dir/s to locate the directory where the modules are
>> installed and include the same in the path
>>
>> Best of luck
>>
>> God Bless You!
>> God Bless India!!
>> --
>>
>> Love & Regards
>> Dr. (h.c.) Khaleel Ahmed H. M.
>>
>> +91-9845007864 <+91%2098450%2007864>
>>
>> Taming Python
>>
>>
>> https://www.amazon.in/Taming-Python-comfortable-writing-Scripts-ebook/dp/B08T6PQG7M
>>
>> ---
>>
>> Human Life is Precious
>> Koran Surah Ma'idah Chapter 5 Verse 32:
>> If anyone killed a person, not in retaliation of murder, or (and) to
>> spread mischief in the land - it would be as if he killed all mankind, & if
>> anyone saved a life, it would be as if he saved the life of all mankind.
>>
>> On Fri, 28 Apr 2023 at 2:54 AM, Reddy Tintaya  wrote:
>>
>>> Should I suppose that it appears like error only in your editor, but the
>>> app runs with no problem?
>>> I guess the error is that your IDE is not pointing to the correct python
>>> interpreter
>>>
>>>
>>> On 27 Apr 2023, at 16:05, Michael Starr  wrote:
>>>
>>> I did pip install django on my venv, which is activated, and it reported
>>> already installed. But the following modules are reporting the error in the
>>> subject line:
>>> django.db
>>> models
>>> django.utils.crypto
>>> django.urls
>>> django.contrib
>>> admin
>>> django.shortcuts
>>> django.views.generic
>>>
>>> I don't know what's wrong. My server runs in development mode (not in
>>> production yet), but there havev been some bugs that are hard to imagine
>>> are caused by this, but still (images not loading, CSS not loading).
>>>
>>> Thanks.
>>>
>>> Michael
>>>
>>>
>>>
>>> --
>>> 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/f7977c43-90ef-4423-bb36-07c550bfda52n%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...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/2FFAC08F-0BC9-44B6-98B2-97A8978AB3DC%40momnt.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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/52f5968e-2e0d-4f64-8fb3-5bbd2ef70bean%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALRYqKgu5HL8e3byiQQ4aam46kSzWHPkJtk3GuCLPWg%2BPw7cxw%40mail.gmail.com.


Hanging SyncConsumers taking down ASGI processing

2023-04-28 Thread Tim Nelson
I am chasing a database deadlock issue in my application. What appears to
be happening is my SyncConsumers are eating up all the ASGI threads because
they are hung and websocket connections start failing.

Is there a way to add a uWSGI "harakiri" like functionality to
SyncConsumers to defend against this issue?

Django==3.2.5
channels==3.0.5
channels-redis==3.3.0
asgiref==3.5.2
uvicorn==0.15.0

Thanks.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK09zopAv42Be3Dt6kk7_BV0_U4AtZh3gRnzmAcaQqms9FF7_A%40mail.gmail.com.