From 7a90220be65a4b898dda2ee90613a0225675c85b Mon Sep 17 00:00:00 2001 From: teddy Date: Tue, 10 Sep 2024 16:20:10 +0100 Subject: [PATCH] Bug fix for f-strings containing unintended closing quotes --- __pycache__/app.cpython-312.pyc | Bin 5250 -> 5250 bytes app.log | 69 ++++++++++++++++++++++++++++++++ app.py | 48 +++++++++++----------- routing/user.py | 4 +- 4 files changed, 95 insertions(+), 26 deletions(-) diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc index 8097bb1e5c1938c49d63ca6812719099728d48b9..0f411028263d669b6441c36b46232154a1329256 100644 GIT binary patch delta 19 ZcmZqDY|`X9&CAQh00b{gHgZ*n001wF1hW7D delta 19 YcmZqDY|`X9&CAQh00gWC8@Vb(04gK{%m4rY diff --git a/app.log b/app.log index e69de29b..6cd8a36f 100644 --- a/app.log +++ b/app.log @@ -0,0 +1,69 @@ +Exception on /store/products [GET] +Traceback (most recent call last): + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app + response = self.full_dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request + rv = self.handle_user_exception(e) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function + return cors_after_request(app.make_response(f(*args, **kwargs))) + ^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request + rv = self.dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request + return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\store\product.py", line 40, in products + filters.is_not_empty = filters.is_not_empty if arg_filter_is_not_empty is None else av.input_bool(arg_filter_is_not_empty, 'is_not_empty', 'filter') + ^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydantic\main.py", line 828, in __getattr__ + raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}') +AttributeError: 'Filters_Product' object has no attribute 'is_not_empty' +Server Error: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. +Request: 127.0.0.1 GET http /store/products? Host: 127.0.0.1:5000 +Connection: keep-alive +Pragma: no-cache +Cache-Control: no-cache +Sec-Ch-Ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128" +Sec-Ch-Ua-Mobile: ?0 +Sec-Ch-Ua-Platform: "Windows" +Upgrade-Insecure-Requests: 1 +Dnt: 1 +User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 +Sec-Fetch-Site: same-origin +Sec-Fetch-Mode: navigate +Sec-Fetch-User: ?1 +Sec-Fetch-Dest: document +Referer: http://127.0.0.1:5000/store/products +Accept-Encoding: gzip, deflate, br, zstd +Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 +Cookie: session=.eJytVlmvqzgS_iutSN1PnXPB7EdqzWQFcgJJSFhfIseGYLYQlgTovv99TM6de_uhZ5NGCsF2FVVfudbfJ7Bt4ltF6hDbdVhN3n-fIFicIc5Jca6bWxVO3puqDX_903H7Yvw8DXNIssn7JMRPWOG3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DNf0hXPywj-4_RdZ0FeK3snh5nIwOQ91D9dehfQu1mZVecbEDieXLRbB9MDcE4MjYXv6bWa0tMWzoNDY6YwIYwE8ZeQrEE2DfOfadBW8yB4LJ169f_wFsnZ0r.Zsz0IQ.CsqbE-G2jF9oYmUiZKS36HfeRw4 + + +Request data: b'' +Traceback: Traceback (most recent call last): + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app + response = self.full_dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request + rv = self.handle_user_exception(e) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function + return cors_after_request(app.make_response(f(*args, **kwargs))) + ^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request + rv = self.dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request + return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\store\product.py", line 40, in products + filters.is_not_empty = filters.is_not_empty if arg_filter_is_not_empty is None else av.input_bool(arg_filter_is_not_empty, 'is_not_empty', 'filter') + ^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydantic\main.py", line 828, in __getattr__ + raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}') +AttributeError: 'Filters_Product' object has no attribute 'is_not_empty' + diff --git a/app.py b/app.py index 3b25b115..7794704e 100644 --- a/app.py +++ b/app.py @@ -69,6 +69,26 @@ app = Flask(__name__) app.config.from_object(app_config) # for db init with required keys # app.config["config"] = app_config() + +# logging +handler = RotatingFileHandler('app.log', maxBytes=10000, backupCount=3) +handler.setLevel(logging.ERROR) +app.logger.addHandler(handler) + +@app.errorhandler(500) +def internal_server_error(error): + app.logger.error('Server Error: %s', (error)) + app.logger.error('Request: %s %s %s %s %s', + request.remote_addr, + request.method, + request.scheme, + request.full_path, + request.headers) + app.logger.error('Request data: %s', request.get_data()) + app.logger.error('Traceback: %s', traceback.format_exc()) + return "500 Internal Server Error", 500 + + """ csrf = CSRFProtect() cors = CORS() @@ -95,33 +115,13 @@ with app.app_context(): client_kwargs={ "scope": "openid profile email", }, - server_metadata_url=f'https://{app.config['DOMAIN_AUTH0']}/.well-known/openid-configuration', - api_base_url = f'https://{app.config['DOMAIN_AUTH0']}', - authorize_url = f'https://{app.config['DOMAIN_AUTH0']}/authorize', - access_token_url = f'https://{app.config['DOMAIN_AUTH0']}/oauth/token', + server_metadata_url=f'https://{app.config["DOMAIN_AUTH0"]}/.well-known/openid-configuration', + api_base_url = f'https://{app.config["DOMAIN_AUTH0"]}', + authorize_url = f'https://{app.config["DOMAIN_AUTH0"]}/authorize', + access_token_url = f'https://{app.config["DOMAIN_AUTH0"]}/oauth/token', ) -# logging -handler = RotatingFileHandler('app.log', maxBytes=10000, backupCount=3) -handler.setLevel(logging.ERROR) -app.logger.addHandler(handler) - -@app.errorhandler(500) -def internal_server_error(error): - app.logger.error('Server Error: %s', (error)) - app.logger.error('Request: %s %s %s %s %s', - request.remote_addr, - request.method, - request.scheme, - request.full_path, - request.headers) - app.logger.error('Request data: %s', request.get_data()) - app.logger.error('Traceback: %s', traceback.format_exc()) - return "500 Internal Server Error", 500 - - - app.register_blueprint(routes_core) app.register_blueprint(routes_legal) app.register_blueprint(routes_store) diff --git a/routing/user.py b/routing/user.py index 72a24b60..4a9f6584 100644 --- a/routing/user.py +++ b/routing/user.py @@ -115,14 +115,14 @@ def login_callback(): # DataStore_Store().add_new_user(id_user) # this is part of get basket - should occur on page load print(f'user session: {session[Model_View_Base.KEY_USER]}') - return redirect(f'{current_app.config['URL_HOST']}{hash_callback}') + return redirect(f"{current_app.config['URL_HOST']}{hash_callback}") except Exception as e: return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Controller error.\n{e}'}) @routes_user.route("/logout") def logout(): session.clear() - url_logout = "https://" + current_app.config['DOMAIN_AUTH0'] + "/v2/logout?" + urlencode( + url_logout = f"https://{current_app.config['DOMAIN_AUTH0']}/v2/logout?" + urlencode( { "returnTo": url_for("routes_user.logout_callback", _external=True), "client_id": current_app.config['ID_AUTH0_CLIENT'],