From owner-freebsd-ports-bugs@FreeBSD.ORG Sun Jul 17 15:10:11 2011 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7BB091065679 for ; Sun, 17 Jul 2011 15:10:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 52E998FC13 for ; Sun, 17 Jul 2011 15:10:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p6HFABMV078507 for ; Sun, 17 Jul 2011 15:10:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p6HFABfp078506; Sun, 17 Jul 2011 15:10:11 GMT (envelope-from gnats) Resent-Date: Sun, 17 Jul 2011 15:10:11 GMT Resent-Message-Id: <201107171510.p6HFABfp078506@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Raphael Kubo da Costa Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 36991106566B for ; Sun, 17 Jul 2011 15:09:10 +0000 (UTC) (envelope-from kubito@gmail.com) Received: from mail-gx0-f182.google.com (mail-gx0-f182.google.com [209.85.161.182]) by mx1.freebsd.org (Postfix) with ESMTP id D93F78FC13 for ; Sun, 17 Jul 2011 15:09:09 +0000 (UTC) Received: by gxk28 with SMTP id 28so1256674gxk.13 for ; Sun, 17 Jul 2011 08:09:09 -0700 (PDT) Received: by 10.236.118.72 with SMTP id k48mr6358763yhh.425.1310915348459; Sun, 17 Jul 2011 08:09:08 -0700 (PDT) Received: from localhost ([189.61.199.245]) by mx.google.com with ESMTPS id o47sm2455821yhn.2.2011.07.17.08.09.05 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 08:09:06 -0700 (PDT) Message-Id: <4e22fb12.47c3ec0a.62b7.ffffac6e@mx.google.com> Date: Sun, 17 Jul 2011 08:09:06 -0700 (PDT) From: Raphael Kubo da Costa To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: lwhsu@FreeBSD.org Subject: ports/158996: [PATCH] www/py-django: Make tests work again when using postgresql-psycopg2 X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jul 2011 15:10:11 -0000 >Number: 158996 >Category: ports >Synopsis: [PATCH] www/py-django: Make tests work again when using postgresql-psycopg2 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jul 17 15:10:10 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Raphael Kubo da Costa >Release: FreeBSD 8.2-STABLE amd64 >Organization: >Environment: System: FreeBSD gibbon 8.2-STABLE FreeBSD 8.2-STABLE #32: Sat Jul 9 17:15:08 BRT >Description: This patch is a backport of Django's changeset 16520 [1] to the 1.3 release (or branch, for that matter). It fixes Django bug 16250 [2], in which psycopg2 2.4.2 made unit tests not work anymore (ie. running `python manage.py test [someapp]' never worked). The patch could be added only when postgresql support is chose in OPTIONS, however as the original commit upstream changes some other backends (oracle and sqlite3) as well as a base, common class, I thought it was better to always include it. As the upstream commit message says: This can be backwards incompatible in the case of user applications that: - Had started using this method - Use a third a party database backend [1] https://code.djangoproject.com/changeset/16520 [2] https://code.djangoproject.com/ticket/16250 Added file(s): - files/patch-changeset_16520.diff Port maintainer (lwhsu@FreeBSD.org) is cc'd. Generated with FreeBSD Port Tools 0.99 >How-To-Repeat: >Fix: --- py27-django-1.3_1.patch begins here --- diff -ruN --exclude=CVS /usr/ports/www/py-django/Makefile /usr/home/rakuco/dev/ports/py-django/www/py-django/Makefile --- /usr/ports/www/py-django/Makefile 2011-03-27 12:02:20.000000000 -0300 +++ /usr/home/rakuco/dev/ports/py-django/www/py-django/Makefile 2011-07-17 12:02:16.000000000 -0300 @@ -7,6 +7,7 @@ PORTNAME= django PORTVERSION= 1.3 +PORTREVISION= 1 CATEGORIES= www python MASTER_SITES= http://media.djangoproject.com/releases/${PORTVERSION:R}/ \ CHEESESHOP diff -ruN --exclude=CVS /usr/ports/www/py-django/files/patch-changeset_16520.diff /usr/home/rakuco/dev/ports/py-django/www/py-django/files/patch-changeset_16520.diff --- /usr/ports/www/py-django/files/patch-changeset_16520.diff 1969-12-31 21:00:00.000000000 -0300 +++ /usr/home/rakuco/dev/ports/py-django/www/py-django/files/patch-changeset_16520.diff 2011-07-16 20:33:14.000000000 -0300 @@ -0,0 +1,84 @@ +diff -uprN Django-1.3-vanilla/django/db/backends/creation.py Django-1.3/django/db/backends/creation.py +--- django/db/backends/creation.py 2011-02-02 12:02:14.000000000 -0200 ++++ django/db/backends/creation.py 2011-07-16 20:21:28.000000000 -0300 +@@ -413,7 +413,7 @@ class BaseDatabaseCreation(object): + # if the database supports it because PostgreSQL doesn't allow + # CREATE/DROP DATABASE statements within transactions. + cursor = self.connection.cursor() +- self.set_autocommit() ++ self._prepare_for_test_db_ddl() + try: + cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix)) + except Exception, e: +@@ -458,20 +458,27 @@ class BaseDatabaseCreation(object): + # to do so, because it's not allowed to delete a database while being + # connected to it. + cursor = self.connection.cursor() +- self.set_autocommit() ++ self._prepare_for_test_db_ddl() + time.sleep(1) # To avoid "database is being accessed by other users" errors. + cursor.execute("DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name)) + self.connection.close() + + def set_autocommit(self): +- "Make sure a connection is in autocommit mode." +- if hasattr(self.connection.connection, "autocommit"): +- if callable(self.connection.connection.autocommit): +- self.connection.connection.autocommit(True) +- else: +- self.connection.connection.autocommit = True +- elif hasattr(self.connection.connection, "set_isolation_level"): +- self.connection.connection.set_isolation_level(0) ++ """ ++ Make sure a connection is in autocommit mode. - Deprecated, not used ++ anymore by Django code. Kept for compatibility with user code that ++ might use it. ++ """ ++ pass ++ ++ def _prepare_for_test_db_ddl(self): ++ """ ++ Internal implementation - Hook for tasks that should be performed before ++ the ``CREATE DATABASE``/``DROP DATABASE`` clauses used by testing code ++ to create/ destroy test databases. Needed e.g. in PostgreSQL to rollback ++ and close any active transaction. ++ """ ++ pass + + def sql_table_creation_suffix(self): + "SQL to append to the end of the test table creation statements" +diff -uprN Django-1.3-vanilla/django/db/backends/oracle/creation.py Django-1.3/django/db/backends/oracle/creation.py +--- django/db/backends/oracle/creation.py 2011-02-19 05:41:17.000000000 -0200 ++++ django/db/backends/oracle/creation.py 2011-07-16 20:32:14.000000000 -0300 +@@ -269,3 +269,6 @@ class DatabaseCreation(BaseDatabaseCreat + settings_dict['NAME'], + self._test_database_user(), + ) ++ ++ def set_autocommit(self): ++ self.connection.connection.autocommit = True +diff -uprN Django-1.3-vanilla/django/db/backends/postgresql/creation.py Django-1.3/django/db/backends/postgresql/creation.py +--- django/db/backends/postgresql/creation.py 2010-07-29 23:54:47.000000000 -0300 ++++ django/db/backends/postgresql/creation.py 2011-07-16 20:28:39.000000000 -0300 +@@ -74,3 +74,11 @@ class DatabaseCreation(BaseDatabaseCreat + else: + output = [] + return output ++ ++ def set_autocommit(self): ++ self._prepare_for_test_db_ddl() ++ ++ def _prepare_for_test_db_ddl(self): ++ """Rollback and close the active transaction.""" ++ self.connection.connection.rollback() ++ self.connection.connection.set_isolation_level(0) +diff -uprN Django-1.3-vanilla/django/db/backends/sqlite3/creation.py Django-1.3/django/db/backends/sqlite3/creation.py +--- django/db/backends/sqlite3/creation.py 2010-12-08 21:48:28.000000000 -0200 ++++ django/db/backends/sqlite3/creation.py 2011-07-16 20:28:57.000000000 -0300 +@@ -68,3 +68,6 @@ class DatabaseCreation(BaseDatabaseCreat + if test_database_name and test_database_name != ":memory:": + # Remove the SQLite database file + os.remove(test_database_name) ++ ++ def set_autocommit(self): ++ self.connection.connection.isolation_level = None --- py27-django-1.3_1.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: