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

Edit Form shows and saves raw default-values from geopackage, spatialite or sqlite #33383

Closed
andreglauser opened this issue Dec 13, 2019 · 2 comments · Fixed by #34012
Closed
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers

Comments

@andreglauser
Copy link

Describe the bug

QGIS shows default values from sqlite tables as string in the edit-form in case of creating a new row. After save, the raw default values are stored in the table.

QGIS-form with new feature and 'wrong' default-values. Feature from sql-insert with id 1 in background.
qgis-form with default values from database

QGIS-table after save_ shown with pointless default-values.
qgis-table view after editing

How to Reproduce

  1. Create table in sqlite, spatialite or geopackage or use provided project default_field_value.zip
-- create the test-table
CREATE TABLE my_table (
    id integer primary key autoincrement,
    comment text,
    created_at_01 text DEFAULT (datetime('now','localtime')),
    created_at_02 text DEFAULT CURRENT_TIMESTAMP
);

-- Test the function of the default values
INSERT INTO my_table (comment) VALUES ('hello world');

SELECT * FROM my_table;

id          comment      created_at_01        created_at_02      
----------  -----------  -------------------  -------------------
1           hello world  2019-12-09 18:00:12  2019-12-09 17:00:12
  1. Load this table into QGIS
  2. Start editing
  3. Add a Feature
  4. -> Form is prefilled with default-value function

Post on gis.stackexchange

QGIS and OS versions

  • QGIS 3.4 LTR (3.4.14 on Windows 10 and Linux / 3.4 on OSGeoLive 13)
  • QGIS 3.10 (Windows 10)

Tried Solutions

  • with "sql-insert" everything works as exepected
  • same behaviour on different workstations
  • same behaviour for geopackage, sqlite- and spatialite-databases
  • same behaviour with or whitout geometry
  • same behaviour in QGIS 3.4.7 (LTR) and 3.10
  • same behaviour in Windows and Linux
  • in spatialite InvalidateLayerStatistics(); and UpdateLayerStatistics(); does not help.
  • Project Properties -> Data Source -> Check "Evaluate default values on provider side".

Additional context

Easiest workaround: Set the default value as well in the field widget. Layer Properties -> Attributes Forms -> field -> Default Value now()

maybe relevant commit 0ae610c

@andreglauser andreglauser added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Dec 13, 2019
@gioman gioman added the Forms label Dec 13, 2019
@elpaso elpaso self-assigned this Jan 23, 2020
@elpaso
Copy link
Contributor

elpaso commented Jan 23, 2020

Just to clarify: the fact that the form shows the default value clauses is the expected behavior, the bug is that when the layer is saved to the backend, the default values are stored verbatim instead of running the functions server side.

Also, the bug affects (at least) two different providers: OGR and spatialite.

@elpaso elpaso added Data Provider Related to specific vector, raster or mesh data providers and removed Forms labels Jan 23, 2020
@elpaso
Copy link
Contributor

elpaso commented Jan 23, 2020

To clarify even more: when the default value source is the provider (like it is in this case) the expression is evaluated server/backend side, there is no way to show the actual value until the layer is saved.

Exception is postgis provider, that has a more complicated logic.

elpaso added a commit to elpaso/QGIS that referenced this issue Jan 27, 2020
Fixes qgis#33383 (for OGR, spatialite commit follows)
elpaso added a commit to elpaso/QGIS that referenced this issue Jan 27, 2020
elpaso added a commit to elpaso/QGIS that referenced this issue Jan 27, 2020
Fixes qgis#33383

Homogenization is not complete but at least
there are test cases for the future.
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! Data Provider Related to specific vector, raster or mesh data providers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants