freelawproject / courtlistener

A fully-searchable and accessible archive of court data including growing repositories of opinions, oral arguments, judges, judicial financial records, and federal filings.
https://www.courtlistener.com
Other
549 stars 151 forks source link

SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async. #3551

Closed sentry-io[bot] closed 10 months ago

sentry-io[bot] commented 10 months ago

This user tried to do page=0 as a GET parameter, which is dumb, but it shouldn't crash, right?


Sentry Issue: COURTLISTENER-5ZY

EmptyPage: That page number is less than 1
  File "cl/opinion_page/views.py", line 239, in view_docket
    docket_entries = await sync_to_async(paginator.page)(page)

SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
(7 additional frame(s) were not displayed)
...
  File "cl/opinion_page/views.py", line 244, in view_docket
    paginator.num_pages
mlissner commented 10 months ago

Looks like no dice on the fix. New Sentry issue:

EmptyPage: That page number is less than 1
  File "cl/opinion_page/views.py", line 239, in view_docket
    docket_entries = await sync_to_async(paginator.page)(page)
  File "django/core/paginator.py", line 89, in page
    number = self.validate_number(number)
  File "django/core/paginator.py", line 69, in validate_number
    raise EmptyPage(self.error_messages["min_page"])

SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
  File "django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
  File "cl/opinion_page/views.py", line 244, in view_docket
    await sync_to_async(paginator.num_pages)
  File "django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "django/core/paginator.py", line 116, in num_pages
    if self.count == 0 and not self.allow_empty_first_page:
  File "django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "django/core/paginator.py", line 110, in count
    return c()
  File "django/db/models/query.py", line 618, in count
    return self.query.get_count(using=self.db)
  File "django/db/models/sql/query.py", line 616, in get_count
    return obj.get_aggregation(using, {"__count": Count("*")})["__count"]
  File "django/db/models/sql/query.py", line 602, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "django/db/models/sql/compiler.py", line 1560, in execute_sql
    cursor = self.connection.cursor()
  File "django/utils/asyncio.py", line 24, in inner
    raise SynchronousOnlyOperation(message)
mlissner commented 10 months ago

Also just got:

EmptyPage: That page number is less than 1
  File "cl/opinion_page/views.py", line 239, in view_docket
    docket_entries = await sync_to_async(paginator.page)(page)
  File "django/core/paginator.py", line 89, in page
    number = self.validate_number(number)
  File "django/core/paginator.py", line 69, in validate_number
    raise EmptyPage(self.error_messages["min_page"])

SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
  File "django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
  File "cl/opinion_page/views.py", line 244, in view_docket
    await sync_to_async(paginator.num_pages)
  File "django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "django/core/paginator.py", line 116, in num_pages
    if self.count == 0 and not self.allow_empty_first_page:
  File "django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "django/core/paginator.py", line 110, in count
    return c()
  File "django/db/models/query.py", line 618, in count
    return self.query.get_count(using=self.db)
  File "django/db/models/sql/query.py", line 616, in get_count
    return obj.get_aggregation(using, {"__count": Count("*")})["__count"]
  File "django/db/models/sql/query.py", line 602, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "django/db/models/sql/compiler.py", line 1560, in execute_sql
    cursor = self.connection.cursor()
  File "django/utils/asyncio.py", line 24, in inner
    raise SynchronousOnlyOperation(message)

Hmmmm....