You've raise a very good point, one that has been on my mind the entire time I've been exploring this. Much of Django has been designed 'on the back of' the ORM, reliant on its limitations and without need to go beyond the scope of what it can provide, its very probable that over time this has introduced some failures to fully adhere to the best possible separation of concerns.
Autofield does seem to suffer from this a little with its assumption of Integer only keys. Fundamentally, when it comes to letting the database do the work for us, Django doesn't need a lot of code to make a field... I've seen alternate (non primary key) autofields as short as 3 lines. If we took the simplest approach possible, a 'project wide setting'. Such a setting could 'toggle' between integer and string/UUID behavior everywhere we need to introduce changes. However I feel that may be too simplistic an approach if I want to try and get broader support for NoSQL/Alternate DB support via the approach I'm so determined to try and build. My biggest worry is really, just how many places check the DB parameters. A cursory reading of the base Field class, has literally dozens of references to both the default connection wrapper object `connection`, and to the database connectionhandler object `connections`. 55 references at last check in `django.db.models.fields` alone. It worries me that I may still need to create essentially a fake database backend full of dozens of stub entries to satisfy the introspection being performed by various classes despite using a queryset that never even makes a database call. If anyone with more knowledge about this wants to comment, it would be most useful. Currently, I'm operating under the assumption, educated at least in part by studying the DB connection classes, testing and debugging various alternative database backends, and debugging my way through ORM calls,that the queryset interface is the uppermost level of ORM interfacing code. In principle nothing above the queryset should rely on any particular database, or any database at all. If there are parts of Django "above" the queryset that rely on knowing things about the database, how defective should we consider this? Should I be temporarily working around such issues, commenting things out, logging bugs etc, or implementing workarounds in my own queryset... such as the aforementioned 'fake database backend'. On Saturday, 19 December 2015 01:42:40 UTC+8, Marc Tamlyn wrote: > > I agree that the current uuidfield is a simplistic solution to be used as > autofield, and having a way to specify your autofield type globally would > be good, equally something like a biginteger field. The complexity involved > with doing this (custom RETURNING statements, database level defaults, > integration with migrations) is an order of magnitude more complex than the > solution committed. I knew that was the intention of the original issue but > it was also why it hadn't been solved for the "simple" case. > > I did spend some time looking at the more complete solution and honestly > could not work out how to approach it. I found if hit many more parts of > the internals of the ORM than I expected. > On 18 Dec 2015 12:32 a.m., "Curtis Maloney" <[email protected] > <javascript:>> wrote: > >> I've identified one new "issue". >>> There is an implicit assumption that primary keys are useful for >>> ordering by the current QuerySet API methods `.first()` and `.last()`. >>> >> >> I believe the case here is that first and last are meaningless without an >> ordering, so in lieu of any programmer supplied ordering, a "fallback" >> consistent ordering of 'pk' is used. >> >> Remember the DBMS is under no obligation to return a query in consistent >> order without an ORDER BY clause. >> >> So, without an ordering, two successive calls to first() [or last()] may, >> in fact, return different records even without modifications to the table. >> >> It's not expected people should _rely_ on the ordering of PK, and, >> indeed, it's frequently recommended against inferring any meaning from PK >> values [sqlite, IIRC, assigns them pseudo-ramdomly] >> >> That said, the assumption that a PK is sortable and will provide a >> deterministic ordering shouldn't be much to ask, surely? >> >> -- >> Curtis >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/django-developers. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/567353FA.6030105%40tinbrain.net >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/22a1247b-67fd-4569-834d-500361cf4417%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
