<p dir="auto"><strong>Migrated issue, originally created by Michał Szczepański (<a href="https://github.com/vane">@vane</a>)</strong></p>
<p dir="auto">When I'm trying to join two tables using String values that are duplicating in each column I get less rows then expected</p>
<p dir="auto">The query from database returns 10 rows but filtered is set to True and after</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        if filtered:
            rows = util.unique_list(rows, filter_fn)
"><pre class="notranslate"><code class="notranslate">        if filtered:
            rows = util.unique_list(rows, filter_fn)

</code></pre></div>
<p dir="auto">in sqlalchemy.orm.loading.py one row is left.</p>
<p dir="auto">I think it's a problem with hashing.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            def filter_fn(row):
                return tuple(fn(x) for x, fn in zip(row, filter_fns))
"><pre class="notranslate"><code class="notranslate">            def filter_fn(row):
                return tuple(fn(x) for x, fn in zip(row, filter_fns))

</code></pre></div>
<p dir="auto">Exist with 1.0.6 and below.</p>
<p dir="auto">Script with full example in attachment with workaround.<br>
Script create tables then execute bugged query and workaround query.<br>
You can vary result number from bugged query by changing result_rows to number from 1 to 10</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="s = Scaffold(db, result_rows=2)
"><pre class="notranslate"><code class="notranslate">s = Scaffold(db, result_rows=2)

</code></pre></div>
<p dir="auto">Test script deletes the database file after run so it's always fresh start.</p>
<p dir="auto">I tried it on 1.0.6 on debian and 0.9.8 on windows same results</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/3477/join_bug.py">join_bug.py</a></p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">It appears that INSERTs and UPDATEs do not work under the following conditions:</p>
<ol dir="auto">
<li>Table with composite primary key.</li>
<li>A hierarchy of classes polymorphically mapped to the table (single inheritance)</li>
<li>The polymorphic discriminator column is part of the primary key.</li>
</ol>
<p dir="auto">Also, while the 'insert' problem can be worked around (see bellow), fixing the 'update' requires patching SQLAlchemy's code.</p>
<p dir="auto">Here's a test case:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('sqlite://')
metadata = MetaData()

test_table = Table(&quot;test&quot;, metadata,
    Column(&quot;id1&quot;, Integer, primary_key=True),
    Column(&quot;id2&quot;, UnicodeText, primary_key=True),
    Column(&quot;data&quot;, UnicodeText)
)

class TestBase(object):
    pass

class TestDeriv(TestBase):
    pass

mapper(TestBase, test_table,
    polymorphic_on=test_table.c.id2,
    polymorphic_identity=u&quot;base&quot;)

mapper(TestDeriv,
    inherits=TestBase,
    polymorphic_on=test_table.c.id2,
    polymorphic_identity=u&quot;deriv&quot;)

metadata.create_all(bind=engine)
session = sessionmaker(bind=engine, autoflush=False)()

t1 = TestDeriv()
t1.id1 = 0
# id2 is implied by instance's type, but we still
# have to assign it explicitly in order the insert to work
t1.id2 = u&quot;deriv&quot;

session.add(t1)
session.commit()
session.clear()
del t1

t1 = session.query(TestDeriv).get((0, u&quot;deriv&quot;))
t1.data = u&quot;foo bar&quot;

# The following line raises ConcurrentModificationError
# Logged SQL shows that id2 is bound to None
session.commit()"><pre class="notranslate"><code class="notranslate">from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('sqlite://')
metadata = MetaData()

test_table = Table("test", metadata,
    Column("id1", Integer, primary_key=True),
    Column("id2", UnicodeText, primary_key=True),
    Column("data", UnicodeText)
)

class TestBase(object):
    pass

class TestDeriv(TestBase):
    pass

mapper(TestBase, test_table,
    polymorphic_on=test_table.c.id2,
    polymorphic_identity=u"base")

mapper(TestDeriv,
    inherits=TestBase,
    polymorphic_on=test_table.c.id2,
    polymorphic_identity=u"deriv")

metadata.create_all(bind=engine)
session = sessionmaker(bind=engine, autoflush=False)()

t1 = TestDeriv()
t1.id1 = 0
# id2 is implied by instance's type, but we still
# have to assign it explicitly in order the insert to work
t1.id2 = u"deriv"

session.add(t1)
session.commit()
session.clear()
del t1

t1 = session.query(TestDeriv).get((0, u"deriv"))
t1.data = u"foo bar"

# The following line raises ConcurrentModificationError
# Logged SQL shows that id2 is bound to None
session.commit()
</code></pre></div>
<p dir="auto">The fix (see the attached file, works against rev. 5098) is next to trivial (it only modifies two lines), but I have no way to be sure that it won't break something else.</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/1162/sqla1.diff">sqla1.diff</a></p>