<p dir="auto">while i can easily fix this in my code, this seems a bug, What happens is that this leaves Object.items as an empty list, whatever it was before. It happens in "sqlalchemy\orm\collections.py" on lines 1157-1163:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            if step == 1:
                for i in range(start, stop, step):
                    if len(self) &gt; start:
                        del self[start]

                for i, item in enumerate(value):
                    self.insert(i + start, item)"><pre class="notranslate"><code class="notranslate">            if step == 1:
                for i in range(start, stop, step):
                    if len(self) &gt; start:
                        del self[start]

                for i, item in enumerate(value):
                    self.insert(i + start, item)
</code></pre></div>
<p dir="auto">Basically if self is the same InstrumentedList as value, then 'del self[start]' also removes value[start], leaving an empty list to be inserted. This would (unverified) also go wrong with any other slice, as long as self and value are the same object.</p>
<p dir="auto">This is not the same behavior is in python itself:</p>
<p dir="auto">L = [1,2,3]<br>
L[:] = L<br>
print(L)</p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">Hi,</p>
<p dir="auto">Imagine the following test-case:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" A
 | \
 B  C
 |
 D"><pre class="notranslate"><code class="notranslate"> A
 | \
 B  C
 |
 D
</code></pre></div>
<p dir="auto">so A is the "root" mapper, B and C inherit from A and D inherits from B (B is a kind of "virtual" class/table), in SQLAlchemy I have something like (not sure for mapper_B):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mapper_A = mapper(A, table_a, polymorphic_on=table_a.c.type_id)
mapper_C = mapper(C, table_c, inherits=A, polymorphic_identity='c')
mapper_B = mapper(B, table_b, inherits=A)
mapper_D = mapper(D, table_d, inherits=B, polymorphic_identity='d')"><pre class="notranslate"><code class="notranslate">mapper_A = mapper(A, table_a, polymorphic_on=table_a.c.type_id)
mapper_C = mapper(C, table_c, inherits=A, polymorphic_identity='c')
mapper_B = mapper(B, table_b, inherits=A)
mapper_D = mapper(D, table_d, inherits=B, polymorphic_identity='d')
</code></pre></div>
<ul dir="auto">
<li>A.query.with_polymorphic(<a href="B,">D</a>) works as expected</li>
<li>A.query.with_polymorphic(<a href="D,">B</a>) doesn't work because the tables are joined in the wrong order (ProgrammingError: (ProgrammingError) missing FROM-clause entry for table b). I think SQLAlchemy should detect that.</li>
<li>A.query.with_polymorphic(<a href="D">D</a>) doesn't work because of a missing table (ProgrammingError: (ProgrammingError) missing FROM-clause entry for table b).</li>
</ul>
<p dir="auto">It would be fantastic if we could do something like:<br>
A.query.with_polymorphic(<a href="D,">E, F, G, ...</a>) regardless of the order of tables/inheritance ...<br>
Now I'm using .iterate_to_root() to bypass that, but it's a little "hackish" because I have to do it for each mapped object .. and merge the whole thing at the end :(</p>
<p dir="auto">Thanks,<br>
Julien</p>