[PyQt] PyQt 5.7, QSqlQueryModel.data() sub-classed override bug?
Phil Thompson
phil at riverbankcomputing.com
Thu May 10 12:34:54 BST 2018
On 10 May 2018, at 11:31 am, J Barchan <jnbarchan at gmail.com> wrote:
>
> Hi Phil,
>
> Sorry, but I have one more related question about surprise behaviour. I will try to keep this as brief as possible.
>
> Yesterday I came to understand why overriding, say, QSqlTableModel.data() came to grief on database-NULL, because of the Python loss of distinction on the QVariants representing "null" versus "default/invalid". I would get back the "default" value where I expected the "null" value.
>
> In sorting my code out now in that light, I began to assume that QSqlTableModel.setData(index, None) would effectively suffer from exactly the same problem, in the opposite direction, i.e. it would set it to the "default" value not the "null" one. And so I would need to deal with too.
>
> However, I find that, whether I do or do not override (in similar fashion) QSqlTableModel.setData(index: QModelIndex, value: QVariant) it does set the value to database-NULL when called via .setData(index, None).
>
> This surprises me, as I expected it to have the same QVariant conversion issue over None as data(index) would. Would you care to explain why this does not appear to be the symmetrical problematic case?
Despite what the docs say, None is converted to an invalid QVariant rather than a null QVariant. I don't know what Qt does when given an invalid QVariant.
Phil
More information about the PyQt
mailing list