jbianchi81 / gesina

0 stars 0 forks source link

Alertar sobre series de salida duplicadas al crear o editar una corrida programada #21

Closed cerobpm closed 6 months ago

cerobpm commented 6 months ago

Las series de salida duplicadas (Key (river, reach, river_stat, execution_plan_id)) generan un error en el scheduler:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/apscheduler/executors/base.py", line 125, in run_job retval = job.func(*job.args, **job.kwargs) File "/src/src/scheduler.py", line 97, in simulate execution_plan = execution_plan_service.create_from_scheduler( File "/app/src/service/execution_plan_service.py", line 89, in create_from_scheduler execution_plan = create( File "/app/src/service/execution_plan_service.py", line 147, in create session.commit() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1451, in commit self._transaction.commit(_to_root=self.future) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 829, in commit self._prepare_impl() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl self.session.flush() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3383, in flush self._flush(objects) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3522, in _flush with util.safereraise(): File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit compat.raise( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 208, in raise_ raise exception File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3483, in _flush flush_context.execute() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute rec.execute(self) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute util.preloaded.orm_persistence.save_obj( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj _emit_insert_statements( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1097, in _emit_insert_statements c = connection._execute_20( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1631, in _execute_20 return meth(self, args_10style, kwargs_10style, execution_options) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 332, in _execute_on_connection return connection._execute_clauseelement( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1498, in _execute_clauseelement ret = self._execute_context( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1862, in _execute_context self._handle_dbapi_exception( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2043, in _handle_dbapiexception util.raise( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 208, in raise_ raise exception File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1799, in _execute_context self.dialect.do_executemany( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 953, in do_executemany context._psycopg2_fetched_rows = xtras.execute_values( File "/usr/local/lib/python3.10/site-packages/psycopg2/extras.py", line 1299, in execute_values cur.execute(b''.join(parts)) sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "execution_plan_output_pkey" DETAIL: Key (river, reach, river_stat, execution_plan_id)=(Guazu, 4, 4, 25) already exists.

[SQL: INSERT INTO gesina.execution_plan_output (river, reach, river_stat, execution_plan_id, stage_series_id, flow_series_id, stage_datum) VALUES (%(river)s, %(reach)s, %(river_stat)s, %(execution_plan_id)s, %(stage_series_id)s, %(flow_series_id)s, %(stage_datum)s)] [parameters: ({'river': 'Guazu', 'reach': '4', 'river_stat': '4', 'execution_plan_id': 25, 'stage_series_id': 2830, 'flow_series_id': -1, 'stage_datum': Decimal('0.7170000000')}, {'river': 'Guazu', 'reach': ' Desembocadura', 'river_stat': '8000', 'execution_plan_id': 25, 'stage_series_id': 1710, 'flow_series_id': -1, 'stage_datum': Decimal('0.3270000000')}, {'river': 'Guazu', 'reach': '3', 'river_stat': '1', 'execution_plan_id': 25, 'stage_series_id': 1712, 'flow_series_id': -1, 'stage_datum': Decimal('0.2090000000')}, {'river': 'Gutierrez', 'reach': ' Desembocadura', 'river_stat': '19967.07', 'execution_plan_id': 25, 'stage_series_id': 44, 'flow_series_id': -1, 'stage_datum': Decimal('0.3900000000')}, {'river': 'Ibicuy', 'reach': ' Ibicuy', 'river_stat': '7.16', 'execution_plan_id': 25, 'stage_series_id': 45, 'flow_series_id': -1, 'stage_datum': Decimal('0.4560000000')}, {'river': 'Lujan', 'reach': '1', 'river_stat': '24.421', 'execution_plan_id': 25, 'stage_series_id': 42, 'flow_series_id': -1, 'stage_datum': Decimal('0E-10')}, {'river': 'Lujan', 'reach': '1', 'river_stat': '18.0191', 'execution_plan_id': 25, 'stage_series_id': 50, 'flow_series_id': -1, 'stage_datum': Decimal('-0.0740000000')}, {'river': 'Lujan', 'reach': '2', 'river_stat': '5.828', 'execution_plan_id': 25, 'stage_series_id': 49, 'flow_series_id': -1, 'stage_datum': Decimal('-0.0990000000')} ... displaying 10 of 78 total bound parameter sets ... {'river': 'SanAntonio', 'reach': ' Desembocadura', 'river_stat': '0', 'execution_plan_id': 25, 'stage_series_id': 1841, 'flow_series_id': -1, 'stage_datum': Decimal('0E-10')}, {'river': 'Lujan', 'reach': ' Desembocadura', 'river_stat': '0', 'execution_plan_id': 25, 'stage_series_id': 1838, 'flow_series_id': -1, 'stage_datum': Decimal('0E-10')})]

Al crear o editar una corrida programada, debería chequearse que no haya duplicados, rechazar la edición/creación e informar del error al usuario, tanto a través de la API como de la GUI.

cerobpm commented 6 months ago

@manulon, @azulzaietz, @federicoburman

federicoburman commented 6 months ago

Ya lo estamos terminando!

federicoburman commented 6 months ago

Esto ya esta!