Fix pasting unsaved changes as temporary scratch layers
Description
Pasting unsaved changes as a temporary scratch layer could fail when source is a db.
Geopackages would have Autogenerate as an fid value, Postgres layers would have nextval(... values etc, which could not be stored in the target int field.
Instead of failing, this PR continues with a null value instead.
Fixes #38913
🪟 Windows builds ready!
Windows builds of this PR are available for testing here. Debug symbols for this build are available here.
(Built from commit 1a0d81d767d42d39921d955bdcb16b2f36866d4e)
Does this work if you modify QgsField::convertCompatible to add something like this just after the initial null check?
if ( QgsVariantUtils::isNull( v ) )
{
v.convert( d->type );
return true;
}
if ( v.userType() == QMetaType::type( "QgsUnsetAttributeValue" ) )
{
return true;
}
Autogenerate and nextval(...) are of userType() == QMetaType::Type::QString, so that will not work.
@uclaros
Autogenerate and nextval(...) are of userType() == QMetaType::Type::QString,
They shouldn't be! Are you checking the field type or value type?
Are you checking the field type or value type?
Value type is string, field type should be int.
I can see QgsUnsetAttributeValue is only used when splitting and duplicating features. It's not clear to me how this class should be used.
@nyalldawson when convertCompatible() fails, it updates the value to the appropriate null QVariant and returns false.
In this case of pasting to the memory provider, we don't really care about the return value: even if the Autogenerate/nextval was of metatype QgsUnsetAttributeValue and it was handled properly as you suggest, it should still update the value to the appropriate null QVariant or it would fail to be stored on the int field.
Hence my suggestion to completely skip the return value check.
🪟 Windows builds
Download Windows builds of this PR for testing. Debug symbols for this build are available here. (Built from commit 1a0d81d767d42d39921d955bdcb16b2f36866d4e)
🪟 Windows Qt6 builds
Download Windows Qt6 builds of this PR for testing. (Built from commit 1a0d81d767d42d39921d955bdcb16b2f36866d4e)
Merging as a temporary fix (see comments in https://github.com/qgis/QGIS/pull/60474)