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

Fix NULL support in WFS server and client #8958

Merged
merged 8 commits into from Jan 24, 2019

Conversation

elpaso
Copy link
Contributor

@elpaso elpaso commented Jan 23, 2019

This PR contains a set of related fixes for NULL WFS support:

  • GML parser set NULL values when parsing empty tags
  • Server WFS NULL values support
    • expose nillable in describefeaturetype
    • serve xsi:nil="true" in getfeature
    • check for NULL in transactions and report an error
    • Support long in transactions
  • Fix WFS client NULL representation
    This was nasty and only reproduceable when features
    were cached (the second time you fetch them) and
    was due to a QVariant( type ) default constructor
    for numeric values being initialized to 0, yielding
    0 instead of NULL.

Reported in #20961

With tests for all fixes (and more)

@@ -584,7 +584,7 @@ QVariant QgsSpatiaLiteFeatureIterator::getFeatureAttribute( sqlite3_stmt *stmt,
}

// assuming NULL
return QVariant( type );
return QVariant( );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that required? Won't that create an invalid QVariant instead of a Null QVariant?

I know we often use them interchangeably, but I was always hoping that in the long run we'll get a clean coherent usage for them. That would open up some nice possibilities for "we know the attribute is NULL" vs. "the attribute was not requested / not yet initialized (still needs default values)" and similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it makes much sense (all passing here on 5.11.2):

  QVERIFY( QVariant().isNull() );
  QVERIFY( !QVariant().isValid() );
  QCOMPARE(QVariant().toString(), QString( "" ) );
  QVERIFY( QVariant(QVariant::LongLong).isNull() );
  QVERIFY( QVariant(QVariant::LongLong).isValid() );
  QCOMPARE(QVariant(QVariant::LongLong).toString(), QString( "0" ) );

Btw, this was the main source of the bug because there are a lot of checks for the QVariant type == field.type() and a conversion to the field type passing through the string representation if the type does not match.

This one-liner change costed me an afternoon (mostly spent on writing tests).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this was the main source of the bug because there are a lot of checks for the QVariant type == field.type() and a conversion to the field type passing through the string representation if the type does not match.

Isn't this the real problem? There should rather be an isNull() check before these. NULL QVariants are produced in many places throughout our codebase and should be accepted as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a second look, is this the semantics?

  • isNull() when the value has been set to NULL
  • !isValid() when we the value has not been set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn ok, I've found another solution that respects the null semantic, with all test cases in place it was much easier now!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @elpaso !
Thanks for the tests and the fix.

@m-kuhn
Copy link
Member

m-kuhn commented Jan 23, 2019

Nice one!

This is part of a bigger fix to support NULL
values in WFS client and server components.
- expose nillable in describefeaturetype
- serve xsi:nil="true" in getfeature
- check for NULL in transactions and report an error

Fixes qgis#20961  - plus some other unreported
No functional changes intended
This was nasty and only reproduceable when features
were cached (so, the second time you get them) and
was due to a QVariant( type ) default constructor
for numeric values being initialized to 0, yielding
0 instead of NULL.

Reported in qgis#20961
@elpaso elpaso force-pushed the bugfix-20961-wfs-null-transactions branch from d912ca3 to 33788c9 Compare January 24, 2019 08:09
This is the right behavior, btw there are other issues
in the server component that ignores the main bool
setting WMSServiceCapabilities completely.
@elpaso elpaso merged commit 861a8b7 into qgis:master Jan 24, 2019
@elpaso elpaso deleted the bugfix-20961-wfs-null-transactions branch January 24, 2019 16:43
elpaso added a commit to elpaso/QGIS that referenced this pull request Feb 6, 2019
…ctions

Fix NULL support in WFS server and client

Cherry-picked from master 861a8b7
@elpaso elpaso mentioned this pull request Feb 6, 2019
nyalldawson pushed a commit that referenced this pull request Feb 6, 2019
Fix NULL support in WFS server and client

Cherry-picked from master 861a8b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants