#36048: CompositePrimaryKey lookup guards raise NotSupportedError instead of a 
more
appropriate exception
-------------------------------------+-------------------------------------
               Reporter:  Jacob      |          Owner:  Jacob Walls
  Walls                              |
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  dev
  layer (models, ORM)                |
               Severity:  Release    |       Keywords:
  blocker                            |
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django mostly(*) raises `NotSupportedError` as documented in
 [https://peps.python.org/pep-0249/#notsupportederror PEP 249], to signify
 that a database feature is missing. Instead, some of the
 `CompositePrimaryKey` sanity checks raise regardless of db feature flags.
 Given that, I'm suggesting that `ValueError` etc. would be more
 appropriate in these two locations:

 -
 
[https://github.com/django/django/blob/8d9901c961bf9d5cfa6bddddbbcebfbf487a5125/django/db/models/fields/related_lookups.py#L120
 RelatedLookupMixin.as_sql]
 -
 
[https://github.com/django/django/blob/8d9901c961bf9d5cfa6bddddbbcebfbf487a5125/django/db/models/aggregates.py#L185
 Count.resolve_expression]

 Our
 
[https://github.com/django/django/blob/8d9901c961bf9d5cfa6bddddbbcebfbf487a5125/django/db/backends/base/operations.py#L663
 guidance] says "specific backends":
 > This is used on specific backends to rule out known expressions that
 have problematic or nonexistent implementations. If the expression has a
 known problem, the backend should raise NotSupportedError.

 Essentially the inverse of #28665. Marking as a release blocker for now to
 ensure we consider this before finalizing the feature.

 ----
 *: The handful of places we're raising `NotSupportedError` regardless of
 db feature flags include:
 - Query.check_filterable
 - QuerySet._not_support_combined_queries
 - QuerySet.get
 - Field.slice_expression
 - ResolvedOuterRef.resolve_expression

 I'm not suggesting to do anything about those at the moment.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36048>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/010701941ee5311e-deebfd2d-80c4-4bb0-bfa6-111b500a016a-000000%40eu-central-1.amazonses.com.

Reply via email to