#1 Pull in fix for using INSERT ... FROM SELECT on older versions of SQLAlchemy.
Closed 6 years ago by ralph. Opened 6 years ago by mikeb.
rpms/ mikeb/python-datanommer-models fix-insert-select  into  master

@@ -0,0 +1,38 @@ 

+ From d35316c3a4db33c7919845f3b7387c3641376571 Mon Sep 17 00:00:00 2001

+ From: Mike Bonnet <mikeb@redhat.com>

+ Date: Thu, 17 Aug 2017 17:06:41 -0700

+ Subject: [PATCH] Set inline=True when using INSERT ... FROM SELECT.

+ 

+ By default, sqlalchemy will try to retrieve the last inserted value

+ from an insert/update/delete. If doing an INSERT/SELECT, this can

+ results in either no values, or multiple values being inserted, and

+ this will break the retrieval. Setting inline=True disables the

+ retrieval.

+ 

+ See:

+ 

+ https://github.com/zzzeek/sqlalchemy/blob/rel_0_9/lib/sqlalchemy/sql/dml.py#L504

+ 

+ for a longer explanation. Note that this is only a problem in sqlalchemy

+ 0.9. 1.0 and higher set inline=True automatically for all relevant

+ cases.

+ ---

+  datanommer.models/datanommer/models/__init__.py | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/datanommer.models/datanommer/models/__init__.py b/datanommer.models/datanommer/models/__init__.py

+ index 7f0dd93..eff3381 100644

+ --- a/datanommer.models/datanommer/models/__init__.py

+ +++ b/datanommer.models/datanommer/models/__init__.py

+ @@ -286,7 +286,7 @@ class Singleton(object):

+          # violations if multiple instances of datanommer are trying to insert the same

+          # value at the same time.

+          not_exists = ~exists(select([cls.__table__.c.name]).where(cls.name == name))

+ -        insert = cls.__table__.insert().\

+ +        insert = cls.__table__.insert(inline=True).\

+                   from_select([cls.__table__.c.name],

+                               select([literal(name)]).where(not_exists))

+          session.execute(insert)

+ -- 

+ 1.8.3.1

+ 

@@ -2,13 +2,14 @@ 

  

  Name:           python-datanommer-models

  Version:        0.8.1

- Release:        1%{?dist}

+ Release:        2%{?dist}

  Summary:        SQLAlchemy models for datanommer

  

  Group:          Development/Libraries

  License:        GPLv3+

  URL:            https://pypi.io/project/%{modname}

  Source0:        https://pypi.io/packages/source/d/%{modname}/%{modname}-%{version}.tar.gz

+ Patch0:         0001-Set-inline-True-when-using-INSERT-.-FROM-SELECT.patch

  

  BuildArch:      noarch

  
@@ -38,6 +39,7 @@ 

  

  %prep

  %setup -q -n %{modname}-%{version}

+ %autopatch -p2

  

  # Make sure that epel/rhel picks up the correct version of sqlalchemy

  %{__awk} 'NR==1{print "import __main__; __main__.__requires__ = __requires__ = [\"sqlalchemy>=0.7\"]; import pkg_resources"}1' setup.py > setup.py.tmp
@@ -81,6 +83,9 @@ 

  %config(noreplace) %{_sysconfdir}/fedmsg.d/datanommer.py*

  

  %changelog

+ * Tue Oct 03 2017 Mike Bonnet <mikeb@redhat.com> - 0.8.1-2

+ - Pull in fix for using INSERT ... FROM SELECT on older versions of SQLAlchemy.

+ 

  * Fri Aug 11 2017 Ralph Bean <rbean@redhat.com> - 0.8.1-1

  - new version