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 comparing the deltas with current data for some some datatypes, mostly dates and times #588

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

suricactus
Copy link
Collaborator

QgsFeature.attribute() will return an instance of QDate, QTime or QDateTime,
depending on the attribute datatype. We need to explicitly handle such situations.

Note geopackages does not support time fields, so this case is untested, but should follow the same logic as date/datetime.

Fixes #572 .

…ostly dates and times

`QgsFeature.attribute()` will return an instance of `QDate`, `QTime` or `QDateTime`,
depending on the attribute datatype. We need to explicitly handle such situations.

Note geopackages does not support `time` fields, so this case is untested, but should follow the same logic as date/datetime.
@suricactus suricactus added bug Something isn't working patch Requires patch version change labels Mar 19, 2023
@duke-nyuki
Copy link
Collaborator

Comment on lines -1271 to +1296
if feature.attribute(attr) != delta_feature_attrs[attr]:
current_value = feature.attribute(attr)
incoming_value = delta_feature_attrs[attr]

# modify the incoming value to the desired type if needed
if incoming_value is not None:
if isinstance(current_value, QDateTime):
incoming_value = QDateTime.fromString(
incoming_value, Qt.ISODateWithMs
)
elif isinstance(current_value, QDate):
incoming_value = QDate.fromString(incoming_value, Qt.ISODate)
elif isinstance(current_value, QTime):
incoming_value = QTime.fromString(incoming_value)

if current_value != incoming_value:
conflicts.append(
f'The attribute "{attr}" that has a conflict:\n-{delta_feature_attrs[attr]}\n+{feature.attribute(attr)}'
f'The attribute "{attr}" that has a conflict:\n-{current_value}\n+{incoming_value}'
Copy link
Collaborator Author

@suricactus suricactus Mar 19, 2023

Choose a reason for hiding this comment

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

@m-kuhn kind request for review. If I understand correctly, there are no more interesting return value types from QgsFeature.attribute(QString). Tried with binary and json, also checked QVariant docs, and seems everything else will be a datatype supported from JSON (as incoming_value is read from delta's JSON).

Copy link
Member

Choose a reason for hiding this comment

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

I think that is correct

@suricactus suricactus merged commit a9c6e9c into master Mar 20, 2023
@suricactus suricactus deleted the QF-2607-qdatetime branch March 20, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch Requires patch version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflict QDateTime and String
3 participants