Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraints: unique constraint not correctly evaluated when 0 #36962

Closed
elpaso opened this issue Jun 4, 2020 · 1 comment · Fixed by #36967
Closed

Constraints: unique constraint not correctly evaluated when 0 #36962

elpaso opened this issue Jun 4, 2020 · 1 comment · Fixed by #36967
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority

Comments

@elpaso
Copy link
Contributor

elpaso commented Jun 4, 2020

Using the same dataset from #36167 with a slightly different join configuration (see the second image) inserting a new feature "ogc_fid" 0 is not recognized as a constraint violation even if a feature with "ogc_fid" 0 is already present in the database table, the expected behavior is to see the orange cross with the unique constraint violation tooltip.

immagine

immagine

@elpaso elpaso added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jun 4, 2020
@elpaso elpaso self-assigned this Jun 4, 2020
@elpaso
Copy link
Contributor Author

elpaso commented Jun 4, 2020

Digging further, this appears a serious bug to me.
It apparently comes from the wrong initialization of the QgsFeature constructor

#ifndef SIP_RUN
    QgsFeature( const QgsFields &fields, QgsFeatureId id = QgsFeatureId() );
#else
    QgsFeature( const QgsFields &fields, qint64 id = 0 );
#endif

assuming that inside QGIS we consider fid values as:

  • < 0: FID_IS_NEW new features that are not yet committed to the data provider
  • >= 0 features that exist in the data provider
    this means that 0 is not FID_NULL but a valid fid value for a not new feature, but the constructor of QgsFeature defaults feature id to 0 which leads to this bug.

I believe it should construct new features with a default of FID_NULL.

elpaso added a commit to elpaso/QGIS that referenced this issue Jun 22, 2020
The QgsFeature default constructors initialized
feature id to 0, which is a valid feature id
instead of initializing it fo FID_NULL.

This was just wrong and broke the validator for
UNIQUE constraints in case a feature with fid 0
existed in the data provider.

Fixes qgis#36962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant