Re: Moving database backends out of the core
How about we do pretend like we want to remove the backends from core and do the homework and refactor the backends to be less intertwined but keep them in the same repo/package. Maybe that’s how we can have the best of both worlds. It is going to be harder to motivate people to put in the work though :/ On 26. Nov 2018, 18:36 +0100, Dan Davis , wrote: > > I think this would only work if most database specific backends were > maintained by the djangoproject itself, allowing for integration tests that > test compatibility. > To my mind, a strong ORM to backend API is a great thing, but we also need > stronger backend integration tests. > -- > You received this message because you are subscribed to a topic in the Google > Groups "Django developers (Contributions to Django itself)" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-developers/O-g06EM6XMM/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > django-developers+unsubscr...@googlegroups.com. > To post to this group, send email to django-developers@googlegroups.com. > 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/23759c70-4148-4ac7-8dfa-ca97f1dae97d%40googlegroups.com. > 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 django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. 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/07aa0648-fdf7-43df-bcbc-efed1acb34cc%40Spark. For more options, visit https://groups.google.com/d/optout.
Re: TestCase.setUpTestData in-memory data isolation.
Thanks for chiming in Adam. I think this is too much of an ask for backwards compatibility. Lots of > things aren't deepcopy-able, as per its docs: > Right. Are these the kind of objects you assign during setUpTestData though? They could be easily moved to setUpTestCase for example. How about adding a container object to TestCase, which deepcopy()'s its > attributes on setUp. It could be called something short like "data', which > would make your example: > That seems like a viable alternative. My only concerns are that it requires adjusting all existing usages of setUpTestData to assign to cls.data instead. It looks like it could be easy to forget doing so until you actually hit a data isolation issue. That makes setUpTestData unsafe to use unless you assign to data. That also creates two data "world" where objects assigned to cls and cls.data lose their references so altering self.data.book.author wouldn't affect self.author if the latter is not assigned to data. What about going through a deprecation period where non-picklable assignment during setUpTestData raises a deprecation warning suggesting using setUpClass or direct class attributes assignment? Another alternative could be to silently ignore deepcopy failures and return the original objects in these cases. Simon Le dimanche 25 novembre 2018 03:53:48 UTC-5, Adam Johnson a écrit : > > I have run into this problem myself in the past. On a previous project we > added a helper function to make deepcopy's of named attributes during > setUp(). > > From a check against a few projects and Django's test suite[2] I have only >> identified a single issue which is that attributes assigned during >> `setUpTestData` would now have to be `deepcopy()`able but it shouldn't be >> a blocker given `Model` instance are. > > > I think this is too much of an ask for backwards compatibility. Lots of > things aren't deepcopy-able, as per its docs: > > This module does not copy types like module, method, stack trace, stack >> frame, file, socket, window, array, or any similar types. It does “copy” >> functions and classes (shallow and deeply), by returning the original >> object unchanged; this is compatible with the way these are treated by the >> pickle module. > > > How about adding a container object to TestCase, which deepcopy()'s its > attributes on setUp. It could be called something short like "data', which > would make your example: > > class BookTests(TestCase): > @classmethod > def setUpTestData(cls): > cls.data.author = Author.objects.create() > cls.data.book = cls.author.books.create() > > def test_relationship_preserved(self): > self.assertIs(self.data.book.author, self.data.author) > > On Sat, 24 Nov 2018 at 03:29, charettes > > wrote: > >> Dear developers, >> >> Django 1.8 introduced the `TestCase.setUpTestData()` class method as a >> mean to >> speed up test fixtures initialization as compared to using `setUp()`[0]. >> >> As I've come to use this feature and review changes from peers using it in >> different projects the fact that test data assigned during its execution >> couldn't be safely altered by test methods without compromising test >> isolation >> has often be the source of confusion and frustration. >> >> While the `setUpTestData` documentation mentions this limitation[1] and >> ways to >> work around it by using `refresh_from_db()` in `setUp()` I believe it >> defeats >> the whole purpose of the feature; avoiding unnecessary roundtrips to the >> database to speed up execution. Given `TestCase` goes through great >> lengths to >> ensure database level data isolation I believe it should do the same with >> class >> level in-memory data assigned during `setUpTestData`. >> >> In order to get rid of this caveat of the feature I'd like to propose an >> adjustment to ensure such in-memory test data isolation. >> >> What I suggest doing is wrapping all attributes assigned during >> `setUpTestData` >> in descriptors that lazily return `copy.deepcopy()`ed values on instance >> attribute accesses. By attaching the `deepcopy()`'s memo on test >> instances we >> can ensure that the reference graph between objects is preserved and thus >> backward compatible. >> >> In other words, the following test would pass even if `self.book` is a >> deep >> copy of `cls.book`. >> >> class BookTests(TestCase): >> @classmethod >> def setUpTestData(cls): >> cls.author = Author.objects.create() >> cls.book = cls.author.books.create() >> >> def test_relationship_preserved(self): >> self.assertIs(self.book.author, self.author) >> >> Lazily returning `deepcopy'ies and caching returned values in `__dict__` >> à la >> `cached_property` should also make sure the slight performance overhead >> this >> incurs is minimized. >> >> From a check against a few projects and Django's test suite[2] I have only >> identified a single issue which is that attributes assigned duri
Re: PEP 484 type hinting in Django
Wow, time fly. I had taken part in the promotion activity 2 years ago. while haven't seen any progress on this topic. Is there on any progress on this topic? 在 2016年8月17日星期三 UTC+8下午12:08:48,Alex Hill写道: > > Hi all, > > I like the plan to include PEP 484 type hinting in Django, outlined in the > PyCharm promotion blog post. [1] > > Has this proposal been fleshed out much? Is there any extra information > available anywhere that I've missed? I think this will be great for Django, > and I'd happily contribute to the effort. > > Cheers, > Alex > > [1] > https://www.djangoproject.com/weblog/2016/jun/30/pycharm-and-django-fundraiser/ > -- 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 django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. 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/e09af7d7-6cd1-4dba-9e80-1cadddaa0a49%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Moving database backends out of the core
Hi, On Mon, 26 Nov 2018 00:57:04 -0800 (PST) Johannes Hoppe wrote: > I want to address a completely different point, and that > *innovation*. I believe that 3rd party backends could lead to more > innovation in the Django ORM. > Currently if you want to introduce a new feature for your database, > you are faced with a lot of complications added by databases you > might not be familiar with. Furthermore you might be requested to > makes those features available for databases you haven't used before. > This drastically increases the bar for contributing innovative new > features. As an example, I wanted to add database defaults for > Postgres and multiple insert return values. I finished the postgres > feature in 2 sprints, but it took me another half year to implement > the same for Oracle. Mainly because I never used Oracle before. > I just wanted to point out that this road to innovation is already open. There's nothing stopping you from writing a custom database backend and releasing it to PyPI. Granted, then your new feature does not become part of Django, but that would also be the case if the standard backends were not part of Django. I should point out that this point is not theoretical -- e.g. an extended Oracle backend existed to support connection pooling[1], and when I wanted to add database instrumentation[2], I first implemented it (though I hadn't published that) in a custom backend, inheriting the existing PG backend. Shai [1] https://github.com/JohnPapps/django-oracle-drcp [2] https://docs.djangoproject.com/en/2.1/topics/db/instrumentation/ -- 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 django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. 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/20181128013339.2901e7a7.shai%40platonix.com. For more options, visit https://groups.google.com/d/optout.