https://issues.qgis.org/https://issues.qgis.org/favicon.ico2019-01-20T23:35:00ZQGIS Issue TrackingQGIS Application - Feature request #18444: Memory layer does not cast attribute typeshttps://issues.qgis.org/issues/18444?journal_id=984672019-01-20T23:35:00ZJürgen Fischerjef@norbit.de
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Please test with QGIS 3.4 - QGIS 2.18 reached it's end of life.</p> QGIS Application - Feature request #18444: Memory layer does not cast attribute typeshttps://issues.qgis.org/issues/18444?journal_id=1005032019-02-23T13:03:41Zmatteo ghettamatteo.ghetta@gmail.com
<ul></ul><p>Tested on QGIS 3.4 (with some small changes to the script):</p>
<pre>
from qgis.core import QgsVectorLayer, QgsFeature
layer = QgsVectorLayer("Point?field=floatfield:double", "poc", "memory")
feat = QgsFeature()
feat.setAttributes(['10'])
layer.dataProvider().addFeatures([feat])
QgsProject.instance().addMapLayer(layer)
# in my usecase I actually loaded the layer from within another processing algo
for f in layer.getFeatures():
print(f['floatfield'], type(f['floatfield']))
</pre>
<p>same behavior of your description. IMHO it is not a bug that QGIS casts automatically the data type. Maybe a warning could be thrown, but this could be a feature request?</p> QGIS Application - Feature request #18444: Memory layer does not cast attribute typeshttps://issues.qgis.org/issues/18444?journal_id=1005152019-02-23T14:42:40ZNorwin Roosenqgis@nroo.de
<ul></ul><p>Thanks for testing in QGIS 3.4 @matteo!<br />To me this issue is about semantic correctness of the API & predictability of its results.<br />Putting a string in a float field is never semantically meaningful, so raising an error may be appropriate.<br />We shure can argue if following the semantics of the API is a feature or a bugfix, but what matters is that there is working software in the end ;)</p> QGIS Application - Feature request #18444: Memory layer does not cast attribute typeshttps://issues.qgis.org/issues/18444?journal_id=1005202019-02-23T16:52:22Zmatteo ghettamatteo.ghetta@gmail.com
<ul><li><strong>Tracker</strong> changed from <i>Bug report</i> to <i>Feature request</i></li></ul><p>thanks Norwin Roosen. OK then I'll mark it as feature request. So it will stay open as reminder.</p>