Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ERREUR: valeur trop longue pour le type character varying(20) #899

@ponceta

Description

@ponceta

Describe the bug

Data error when exporting some fields with longer than expected values.

  1. Error log is messy for the user
  2. We should provide a way to find and fix these data or at least check conformity before export
  3. When exporting wrong data, the LEFT(value,20) in that particular case should be exported
2025-09-29T08:02:46     WARNING    Traceback (most recent call last):
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 1971, in _exec_single_context
              self.dialect.do_execute(
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\default.py", line 919, in do_execute
              cursor.execute(statement, parameters)
             psycopg2.errors.StringDataRightTruncation: ERREUR: valeur trop longue pour le type character varying(20)
             
             
             The above exception was the direct cause of the following exception:
             
             Traceback (most recent call last):
              File "C:\Users/pulpoar/AppData/Roaming/QGIS/QGIS3\profiles\pulpoar_qgep/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\gui\__init__.py", line 690, in action_do_export
              qgep_export_dss(
              File "C:\Users/pulpoar/AppData/Roaming/QGIS/QGIS3\profiles\pulpoar_qgep/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\qgepdss\export.py", line 1017, in qgep_export_dss
              qgep_export_utils.export_channel()
              File "C:\Users/pulpoar/AppData/Roaming/QGIS/QGIS3\profiles\pulpoar_qgep/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\utils\qgep_export_utils.py", line 368, in export_channel
              self.abwasser_session.flush()
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\session.py", line 4296, in flush
              self._flush(objects)
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\session.py", line 4431, in _flush
              with util.safe_reraise():
              ^^^^^^^^^^^^^^^^^^^
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__
              raise exc_value.with_traceback(exc_tb)
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\session.py", line 4392, in _flush
              flush_context.execute()
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\unitofwork.py", line 466, in execute
              rec.execute(self)
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\unitofwork.py", line 642, in execute
              util.preloaded.orm_persistence.save_obj(
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\persistence.py", line 93, in save_obj
              _emit_insert_statements(
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\orm\persistence.py", line 1227, in _emit_insert_statements
              result = connection.execute(
              ^^^^^^^^^^^^^^^^^^^
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 1422, in execute
              return meth(
              ^^^^^
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\sql\elements.py", line 514, in _execute_on_connection
              return connection._execute_clauseelement(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 1644, in _execute_clauseelement
              ret = self._execute_context(
              ^^^^^^^^^^^^^^^^^^^^^^
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 1850, in _execute_context
              return self._exec_single_context(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 1990, in _exec_single_context
              self._handle_dbapi_exception(
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 2357, in _handle_dbapi_exception
              raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\base.py", line 1971, in _exec_single_context
              self.dialect.do_execute(
              File "C:\OSGeo4W\apps\Python312\Lib\site-packages\sqlalchemy\engine\default.py", line 919, in do_execute
              cursor.execute(statement, parameters)
             sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) ERREUR: valeur trop longue pour le type character varying(20)
             
             [SQL: INSERT INTO pg2ili_dss.abwasserbauwerk (t_id, akten, baujahr, baulicherzustand, baulos, bemerkung, bezeichnung, bruttokosten, detailgeometrie, ersatzjahr, finanzierung, inspektionsintervall, sanierungsbedarf, standortname, astatus, subventionen, wbw_basisjahr, wbw_bauart, wiederbeschaffungswert, zugaenglichkeit, betreiberref, eigentuemerref) VALUES (%(t_id)s, %(akten)s, %(baujahr)s, %(baulicherzustand)s, %(baulos)s, %(bemerkung)s, %(bezeichnung)s, %(bruttokosten)s, ST_Force2D(NULL), %(ersatzjahr)s, %(finanzierung)s, %(inspektionsintervall)s, %(sanierungsbedarf)s, %(standortname)s, %(astatus)s, %(subventionen)s, %(wbw_basisjahr)s, %(wbw_bauart)s, %(wiederbeschaffungswert)s, %(zugaenglichkeit)s, %(betreiberref)s, %(eigentuemerref)s)]
             [parameters: {'t_id': 15, 'akten': None, 'baujahr': 0, 'baulicherzustand': 'unbekannt', 'baulos': None, 'bemerkung': None, 'bezeichnung': 'RC 446_cff-RC 382_cff', 'bruttokosten': None, 'ersatzjahr': None, 'finanzierung': None, 'inspektionsintervall': None, 'sanierungsbedarf': None, 'standortname': 'RC 446_cff-RC 382_cf', 'astatus': 'in_Betrieb', 'subventionen': None, 'wbw_basisjahr': None, 'wbw_bauart': None, 'wiederbeschaffungswert': None, 'zugaenglichkeit': None, 'betreiberref': 13, 'eigentuemerref': 11}]
             (Background on this error at: https://sqlalche.me/e/20/9h9h)

To Reproduce
Exact steps to reproduce the behavior:

  1. Export data with custom field lengths
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots / data
If applicable, add screenshots or data to help explain your problem.

Desktop (please complete the following information):

  • QGEP plugin version
  • QGEP datamodel version
  • QGEP project file version
  • QGIS Version
  • OS

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions