-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
It is possible to store text into a numeric field, while it shouldn't be, using the Date/Time edit widget #36715
Comments
I guess this is a particular behavior of the memory provider because it stores everything in memory as What do you think should be the expected behavior in case conversion to the field type cannot be successfully performed for the memory provider? |
I think it should not allow to store text strings in a numeric field (like it isn't allowed to store a value > MAX_INT32 into an INT32 field). It seems this could lead to loss of data: I've found that it is also possible to store text strings in a numeric field of a memory layer using the "Value Map" widget. |
@agiudiceandrea I've started working on this issue. The big problem is that every provider does a different thing regarding wrong attribute type, when you try to store a string into a numeric field:
I think that Postgis is doing right here, just silently fail and convert a string to |
Looks like patching the data provider to refuse commits on incompatible attribute types is not enough: the vector file writer just ignores any error. |
Thank you for looking at this! I think maybe it could be less problematic just modifying the widgets so that they aren't available for certain types of fields or that they behave accordingly to the type of field. For example, the Date/Time widget could store a string and a date/time respectively into a string and a date/time field, like now, and julian day or millisecond in numeric field and should be unavailable for e.g. a boolean field. |
Fixes qgis#36715 Adds a method to check for QVariant conversions, also check for integral type narrowing so that for example floating point 123.45 does not get down casted to integer without raising an error.
Fixes #36715 Adds a method to check for QVariant conversions, also check for integral type narrowing so that for example floating point 123.45 does not get down casted to integer without raising an error.
Fixes qgis#36715 Adds a method to check for QVariant conversions, also check for integral type narrowing so that for example floating point 123.45 does not get down casted to integer without raising an error.
Describe the bug
It seems it is possible to store text into a numeric field, at least for memory layers, while I think it shouldn't be.
How to Reproduce
then
stop editing and save the change: as you can see, a date e.g. 2020-05-25 is stored into the field
open the field calculator and enter the filed name as an expression: as you can see, the output preview shows '2020-05-25' (its enclosed in single quotes, so it's a text string)
in the python console:
outputs
'integer'
outputs
'2020-05-25'
outputs
<class 'str'>
QGIS and OS versions
Tested with QGIS
The text was updated successfully, but these errors were encountered: