<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">According to the ANSI standards SQL:92, SQL:1999, and SQL:2003, a UNIQUE constraint should disallow duplicate non-NULL values, but allow multiple NULL values. SQL Server has always implemented a crippled version of this, allowing a single NULL but disallowing multiple NULL values. From <a href="http://connect.microsoft.com/SQLServer/feedback/details/299229/change-unique-constraint-to-allow-multiple-null-values" rel="nofollow">http://connect.microsoft.com/SQLServer/feedback/details/299229/change-unique-constraint-to-allow-multiple-null-values</a></p>
<p dir="auto">To fix this issue SQL has added the filtered indexes feature. Using this feature it is possible to perform the logic of an index to a filter set of items in a table using a WHERE clause. i.e.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="create unique nonclustered index idx on dbo.DimCustomer(emailAddress)
where EmailAddress is not null;"><pre class="notranslate"><code class="notranslate">create unique nonclustered index idx on dbo.DimCustomer(emailAddress)
where EmailAddress is not null;
</code></pre></div>
<p dir="auto">Attached is a patch which applies the above feature when SQL 2008 or newer is used as a server. This patch has been tested on Windows 7/SQL Server 2012 using pyodbc and the normal SQL Server driver.</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/2608/sqlalchemy-feature1.patch">sqlalchemy-feature1.patch</a></p>
<h3 dir="auto">Describe the typing issue</h3>
<p dir="auto">In mypy 1.1.1 we're seeing a lot of typing errors along the lines of:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" auth.py:136: error: Argument &quot;email&quot; to &quot;User&quot; has incompatible type
&quot;str&quot;; expected &quot;Mapped[str]&quot;  [arg-type]
        user = User(email=email, ***"><pre class="notranslate"><code class="notranslate"> auth.py:136: error: Argument "email" to "User" has incompatible type
"str"; expected "Mapped[str]"  [arg-type]
        user = User(email=email, ***
</code></pre></div>
<p dir="auto">Errors are not present in mypy 1.0.0.</p>
<p dir="auto">I suspect it has to do with some new features around dataclasses.</p>
<h3 dir="auto">To Reproduce</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Base defined like:
class Base(MappedAsDataclass, DeclarativeBase):
    ..."><pre class="notranslate"><span class="pl-c"># Base defined like:</span>
<span class="pl-k">class</span> <span class="pl-v">Base</span>(<span class="pl-v">MappedAsDataclass</span>, <span class="pl-v">DeclarativeBase</span>):
    ...</pre></div>
<p dir="auto">Let me know if you can't reproduce, and I'll try to look into it further.</p>
<h3 dir="auto">Versions</h3>
<ul dir="auto">
<li>SQLAlchemy: 2.0.5</li>
</ul>