<p dir="auto">I have two pgsql domains: <code class="notranslate">isoweekday</code> that is based on INT and <code class="notranslate">isoweekdays</code> that is an array of the former. Both domains add some checks like no duplicate values, no empty list, only values from &lt;1, 7&gt; range.</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CREATE DOMAIN isoweekday AS INT
CHECK(...);

CREATE DOMAIN isoweekdays AS isoweekday[]
CHECK(...);"><pre class="notranslate"><span class="pl-k">CREATE</span> <span class="pl-k">DOMAIN</span> <span class="pl-en">isoweekday</span> <span class="pl-k">AS</span> <span class="pl-k">INT</span>
<span class="pl-k">CHECK</span>(...);

<span class="pl-k">CREATE</span> <span class="pl-k">DOMAIN</span> <span class="pl-en">isoweekdays</span> <span class="pl-k">AS</span> isoweekday[]
<span class="pl-k">CHECK</span>(...);</pre></div>
<p dir="auto">I've created custom types, like so:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class ISOWeekDayDomain(types.UserDefinedType, types.Integer):
    def get_col_spec(self, **kwargs):
        return 'isoweekday'


class ISOWeekDaysDomain(types.UserDefinedType, ARRAY):
    def __init__(self, **kwargs):
        if 'item_type' not in kwargs:
            kwargs['item_type'] = ISOWeekDayDomain

        super(ISOWeekDaysDomain, self).__init__(**kwargs)

    def get_col_spec(self, **kwargs):
        return 'isoweekdays'"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">ISOWeekDayDomain</span>(<span class="pl-s1">types</span>.<span class="pl-v">UserDefinedType</span>, <span class="pl-s1">types</span>.<span class="pl-v">Integer</span>):
    <span class="pl-k">def</span> <span class="pl-en">get_col_spec</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-k">return</span> <span class="pl-s">'isoweekday'</span>


<span class="pl-k">class</span> <span class="pl-v">ISOWeekDaysDomain</span>(<span class="pl-s1">types</span>.<span class="pl-v">UserDefinedType</span>, <span class="pl-v">ARRAY</span>):
    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-k">if</span> <span class="pl-s">'item_type'</span> <span class="pl-c1">not</span> <span class="pl-c1">in</span> <span class="pl-s1">kwargs</span>:
            <span class="pl-s1">kwargs</span>[<span class="pl-s">'item_type'</span>] <span class="pl-c1">=</span> <span class="pl-v">ISOWeekDayDomain</span>

        <span class="pl-en">super</span>(<span class="pl-v">ISOWeekDaysDomain</span>, <span class="pl-s1">self</span>).<span class="pl-en">__init__</span>(<span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)

    <span class="pl-k">def</span> <span class="pl-en">get_col_spec</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-k">return</span> <span class="pl-s">'isoweekdays'</span></pre></div>
<p dir="auto">and then used them to define a column:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Column(
    ISOWeekDaysDomain, nullable=False, server_default=text('ARRAY[1,2,3,4,5,6,7]')
)"><pre class="notranslate"><span class="pl-v">Column</span>(
    <span class="pl-v">ISOWeekDaysDomain</span>, <span class="pl-s1">nullable</span><span class="pl-c1">=</span><span class="pl-c1">False</span>, <span class="pl-s1">server_default</span><span class="pl-c1">=</span><span class="pl-en">text</span>(<span class="pl-s">'ARRAY[1,2,3,4,5,6,7]'</span>)
)</pre></div>
<p dir="auto">Creating migrations using Alembic went well, and it created the following statement:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    op.add_column(
        u'config',
        sa.Column(
            'dow',
            ISOWeekDaysDomain(),
            server_default=sa.text(u'ARRAY[1, 2, 3, 4, 5, 6, 7]'),
            nullable=False,
        ),
    )"><pre class="notranslate">    <span class="pl-s1">op</span>.<span class="pl-en">add_column</span>(
        <span class="pl-s">u'config'</span>,
        <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(
            <span class="pl-s">'dow'</span>,
            <span class="pl-v">ISOWeekDaysDomain</span>(),
            <span class="pl-s1">server_default</span><span class="pl-c1">=</span><span class="pl-s1">sa</span>.<span class="pl-en">text</span>(<span class="pl-s">u'ARRAY[1, 2, 3, 4, 5, 6, 7]'</span>),
            <span class="pl-s1">nullable</span><span class="pl-c1">=</span><span class="pl-c1">False</span>,
        ),
    )</pre></div>
<p dir="auto">After applying migrations on the database, I'm getting the following warning:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sqlalchemy/dialects/postgresql/base.py:2683: SAWarning: Did not recognize type 'isoweekday[]' of column 'dow'"><pre class="notranslate"><code class="notranslate">sqlalchemy/dialects/postgresql/base.py:2683: SAWarning: Did not recognize type 'isoweekday[]' of column 'dow'
</code></pre></div>
<p dir="auto">Running alembic yields a new database migration that alters the previously added column with <code class="notranslate">sqltypes.NULLTYPE</code>.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="op.alter_column(u'tent_crawling_config', 'dow',
           existing_type=sa.NullType(),
           nullable=False,
           existing_server_default=sa.text(u'ARRAY[1, 2, 3, 4, 5, 6, 7]'))"><pre class="notranslate"><span class="pl-s1">op</span>.<span class="pl-en">alter_column</span>(<span class="pl-s">u'tent_crawling_config'</span>, <span class="pl-s">'dow'</span>,
           <span class="pl-s1">existing_type</span><span class="pl-c1">=</span><span class="pl-s1">sa</span>.<span class="pl-v">NullType</span>(),
           <span class="pl-s1">nullable</span><span class="pl-c1">=</span><span class="pl-c1">False</span>,
           <span class="pl-s1">existing_server_default</span><span class="pl-c1">=</span><span class="pl-s1">sa</span>.<span class="pl-en">text</span>(<span class="pl-s">u'ARRAY[1, 2, 3, 4, 5, 6, 7]'</span>))</pre></div>
<p dir="auto">The <code class="notranslate">domains</code> dictionary passed to <code class="notranslate">_get_column_info</code> contains both created domains and during execution it enters the <a href="https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/dialects/postgresql/base.py#L2677">dialects/postgresql/base.py#L2677</a> block.</p>
<p dir="auto">What am I missing? How to register my custom types that map domains so the reflection API recognises them?</p>
<p dir="auto">I'm using <code class="notranslate">SQLAlchemy==1.2.14</code> and PostgreSQL <code class="notranslate">v11</code></p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">Hello, I've just encountered a very odd behaviour of SA, revision 1190.</p>
<p dir="auto">Basically, it seems to save dereferenced object as well, even though the object gets deleted from the current namespace. <em>all the object values</em> are actually kept and written to the database!</p>
<p dir="auto">I don't have enoug SA knowledge to try to understand where the problem occurs; I guess it's got something to do with SA internal object-tracking (maybe it's employing a standard ref instead of a weakref somewhere).</p>
<p dir="auto">demo attached.</p>
<p dir="auto">Alan Franzoni &lt;alan.franzoni at gmail dot com&gt;</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/128/objectstore-problem.py">objectstore-problem.py</a></p>