Message:
sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) BŁĄD: wstawianie lub modyfikacja na tabeli "oil_analysis_harmonogram" narusza klucz obcy "FK_device_id" DETAIL: Klucz (device_id_fkey)=(69436) nie występuje w tabeli "devices". [SQL: INSERT INTO cbm.oil_analysis_harmonogram (oil_analysis_harmonogram_id_pkey, ship_id_fkey, device_id_fkey, report_number, report_type_id_fkey) VALUES (%(oil_analysis_harmonogram_id_pkey)s, %(ship_id_fkey)s, %(device_id_fkey)s, %(report_number)s, %(report_type_id_fkey)s)] [parameters: {'oil_analysis_harmonogram_id_pkey': 688, 'ship_id_fkey': 344, 'device_id_fkey': '69436', 'report_number': '18241482127', 'report_type_id_fkey': '292'}] (Background on this error at: https://sqlalche.me/e/14/gkpj)
_execute_context if fn(cursor, statement, parameters, context): evt_handled = True break if not evt_handled: self.dialect.do_execute( cursor, statement, parameters, context ) if self._has_events or self.engine._has_events: self.dispatch.after_cursor_execute( self,do_execute def do_executemany(self, cursor, statement, parameters, context=None): cursor.executemany(statement, parameters) def do_execute(self, cursor, statement, parameters, context=None): cursor.execute(statement, parameters) def do_execute_no_params(self, cursor, statement, context=None): cursor.execute(statement) def is_disconnect(self, e, connection, cursor):__call__ def __call__(self, environ: dict, start_response: t.Callable) -> t.Any: """The WSGI server calls the Flask application object as the WSGI application. This calls :meth:`wsgi_app`, which can be wrapped to apply middleware. """ return self.wsgi_app(environ, start_response)wsgi_app try: ctx.push() response = self.full_dispatch_request() except Exception as e: error = e response = self.handle_exception(e) except: # noqa: B001 error = sys.exc_info()[1] raise return response(environ, start_response) finally:wsgi_app ctx = self.request_context(environ) error: t.Optional[BaseException] = None try: try: ctx.push() response = self.full_dispatch_request() except Exception as e: error = e response = self.handle_exception(e) except: # noqa: B001 error = sys.exc_info()[1]full_dispatch_request request_started.send(self) rv = self.preprocess_request() if rv is None: rv = self.dispatch_request() except Exception as e: rv = self.handle_user_exception(e) return self.finalize_request(rv) def finalize_request( self, rv: t.Union[ResponseReturnValue, HTTPException],full_dispatch_request self.try_trigger_before_first_request_functions() try: request_started.send(self) rv = self.preprocess_request() if rv is None: rv = self.dispatch_request() except Exception as e: rv = self.handle_user_exception(e) return self.finalize_request(rv) def finalize_request(dispatch_request getattr(rule, "provide_automatic_options", False) and req.method == "OPTIONS" ): return self.make_default_options_response() # otherwise dispatch to the handler for that endpoint return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) def full_dispatch_request(self) -> Response: """Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling.get_oil_report_details@app.route('/put_oil_report_json', methods=['GET', 'POST']) def get_oil_report_details():
content = request.json put_new_oil_report(content) return 'True' def put_new_oil_report(content):
harmo_series = pd.read_json(content['harmo_json']).iloc[0]put_new_oil_report ) Harmonogram_row.oil_analysis_harmonogram_id_pkey = int(harmo_series.oil_analysis_harmonogram_id_pkey) db.session.add(Harmonogram_row) db.session.commit() for mc, row_series_meas in oil_meas_device_df.iterrows(): meas_oil_dev_row = OilMeasurementsDevice( row_series_meas.harmo_id_fkey,commitcommit """ if self._transaction is None: if not self._autobegin(): raise sa_exc.InvalidRequestError("No transaction is begun.") self._transaction.commit(_to_root=self.future) def prepare(self): """Prepare the current transaction in progress for two phase commit. If no transaction is in progress, this method raises ancommit self._state = PREPARED def commit(self, _to_root=False): self._assert_active(prepared_ok=True) if self._state is not PREPARED: self._prepare_impl() if self._parent is None or self.nested: for conn, trans, should_commit, autoclose in set( self._connections.values() ):_prepare_impl if not self.session._flushing: for _flush_guard in range(100): if self.session._is_clean(): break self.session.flush() else: raise exc.FlushError( "Over 100 subsequent flushes have occurred within " "session.commit() - is an after_flush() hook " "creating new objects?"flush if self._is_clean(): return try: self._flushing = True self._flush(objects) finally: self._flushing = False def _flush_warning(self, method): util.warn(_flush transaction.commit() except: with util.safe_reraise(): transaction.rollback(_capture_exception=True) def bulk_save_objects( self, objects, return_defaults=False,__exit__ exc_type, exc_value, exc_tb = self._exc_info self._exc_info = None # remove potential circular references if not self.warn_only: compat.raise_( exc_value, with_traceback=exc_tb, ) else: if not compat.py3k and self._exc_info and self._exc_info[1]: # emulate Py3K's behavior of telling us when an exception # occurs in an exception handler.raise_ # intermediary exception does not change, but we can't figure # that out. exception.__cause__ = replace_context try: raise exception finally: # credit to # https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/ # as the __traceback__ object creates a cycle del exception, replace_context, from_, with_traceback_flush flush_context.transaction = transaction = self.begin(_subtrans=True) try: self._warn_on_events = True try: flush_context.execute() finally: self._warn_on_events = False self.dispatch.after_flush(self, flush_context) execute while set_: n = set_.pop() n.execute_aggregate(self, set_) else: for rec in topological.sort(self.dependencies, postsort_actions): rec.execute(self) def finalize_flush_changes(self): """Mark processed objects as clean / deleted after a successful flush(). execute @util.preload_module("sqlalchemy.orm.persistence") def execute(self, uow): util.preloaded.orm_persistence.save_obj( self.mapper, uow.states_for_mapper_hierarchy(self.mapper, False, False), uow, ) def per_state_flush_actions(self, uow): states = list( uow.states_for_mapper_hierarchy(self.mapper, False, False)save_obj _emit_insert_statements( base_mapper, uowtransaction, mapper, table, insert, ) _finalize_insert_update_commands( base_mapper, uowtransaction,_emit_insert_statements # so we have to post-fetch / use lastrowid anyway. records = list(records) multiparams = [rec[2] for rec in records] c = connection._execute_20( statement, multiparams, execution_options=execution_options ) if bookkeeping: for ( (_execute_20 except AttributeError as err: util.raise_( exc.ObjectNotExecutableError(statement), replace_context=err ) else: return meth(self, args_10style, kwargs_10style, execution_options) def exec_driver_sql( self, statement, parameters=None, execution_options=None ): r"""Executes a SQL statement construct and returns a_execute_on_connection def _execute_on_connection( self, connection, multiparams, params, execution_options, _force=False ): if _force or self.supports_execution: return connection._execute_clauseelement( self, multiparams, params, execution_options ) else: raise exc.ObjectNotExecutableError(self) def unique_params(self, *optionaldict, **kwargs):_execute_clauseelement execution_options, compiled_sql, distilled_params, elem, extracted_params, cache_hit=cache_hit, ) if has_events: self.dispatch.after_execute( self, elem,_execute_context # close us now branched.close() except BaseException as e: self._handle_dbapi_exception( e, statement, parameters, cursor, context ) return result def _cursor_execute(self, cursor, statement, parameters, context=None):_handle_dbapi_exception if newraise: util.raise_(newraise, with_traceback=exc_info[2], from_=e) elif should_wrap: util.raise_( sqlalchemy_exception, with_traceback=exc_info[2], from_=e ) else: util.raise_(exc_info[1], with_traceback=exc_info[2]) finally:raise_ # intermediary exception does not change, but we can't figure # that out. exception.__cause__ = replace_context try: raise exception finally: # credit to # https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/ # as the __traceback__ object creates a cycle del exception, replace_context, from_, with_traceback_execute_context if fn(cursor, statement, parameters, context): evt_handled = True break if not evt_handled: self.dialect.do_execute( cursor, statement, parameters, context ) if self._has_events or self.engine._has_events: self.dispatch.after_cursor_execute( self,do_execute def do_executemany(self, cursor, statement, parameters, context=None): cursor.executemany(statement, parameters) def do_execute(self, cursor, statement, parameters, context=None): cursor.execute(statement, parameters) def do_execute_no_params(self, cursor, statement, context=None): cursor.execute(statement) def is_disconnect(self, e, connection, cursor):sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) BŁĄD: wstawianie lub modyfikacja na tabeli "oil_analysis_harmonogram" narusza klucz obcy "FK_device_id" DETAIL: Klucz (device_id_fkey)=(69436) nie występuje w tabeli "devices". [SQL: INSERT INTO cbm.oil_analysis_harmonogram (oil_analysis_harmonogram_id_pkey, ship_id_fkey, device_id_fkey, report_number, report_type_id_fkey) VALUES (%(oil_analysis_harmonogram_id_pkey)s, %(ship_id_fkey)s, %(device_id_fkey)s, %(report_number)s, %(report_type_id_fkey)s)] [parameters: {'oil_analysis_harmonogram_id_pkey': 688, 'ship_id_fkey': 344, 'device_id_fkey': '69436', 'report_number': '18241482127', 'report_type_id_fkey': '292'}] (Background on this error at: https://sqlalche.me/e/14/gkpj)
This is the Copy/Paste friendly version of the traceback.
The console is locked and needs to be unlocked by entering the PIN. You can find the PIN printed out on the standard output of your shell that runs the server.