diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..0f26793e --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,78 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + # Runs at 22:21 on Monday. + - cron: '21 22 * * 1' + +jobs: + analyze: + name: Analyze + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'javascript', 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # âšī¸ Command-line programs to run using the OS shell. + # đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/CHANGELOG.md b/CHANGELOG.md index dcda688d..10bb1d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,17 @@ Using the following categories, list your changes in this order: ## [Unreleased] -- Nothing (yet) +- Nothing yet! + +## [3.2.1] - 2023-06-29 + +### Added + +- Template tag exception details are now rendered on the webpage when `settings.py:DEBUG` is enabled. + +### Fixed + +- Prevent exceptions within the `component` template tag from causing the whole template to fail to render. ## [3.2.0] - 2023-06-08 @@ -289,7 +299,8 @@ Using the following categories, list your changes in this order: - Support for IDOM within the Django -[unreleased]: https://github.com/reactive-python/reactpy-django/compare/3.2.0...HEAD +[unreleased]: https://github.com/reactive-python/reactpy-django/compare/3.2.1...HEAD +[3.2.1]: https://github.com/reactive-python/reactpy-django/compare/3.2.0...3.2.1 [3.2.0]: https://github.com/reactive-python/reactpy-django/compare/3.1.0...3.2.0 [3.1.0]: https://github.com/reactive-python/reactpy-django/compare/3.0.1...3.1.0 [3.0.1]: https://github.com/reactive-python/reactpy-django/compare/3.0.0-reactpy...3.0.1 diff --git a/docs/python/settings.py b/docs/python/settings.py index 9633da43..a08dbc55 100644 --- a/docs/python/settings.py +++ b/docs/python/settings.py @@ -17,6 +17,6 @@ # Dotted path to the Django authentication backend to use for ReactPy components # This is only needed if: # 1. You are using `AuthMiddlewareStack` and... -# 2. You are using Django's `AUTHENTICATION_BACKENDS` settings and... +# 2. You are using Django's `AUTHENTICATION_BACKENDS` setting and... # 3. Your Django user model does not define a `backend` attribute REACTPY_AUTH_BACKEND = None diff --git a/src/reactpy_django/__init__.py b/src/reactpy_django/__init__.py index 0d8bb188..8d026baa 100644 --- a/src/reactpy_django/__init__.py +++ b/src/reactpy_django/__init__.py @@ -2,7 +2,7 @@ from reactpy_django.websocket.paths import REACTPY_WEBSOCKET_PATH -__version__ = "3.2.0" +__version__ = "3.2.1" __all__ = [ "REACTPY_WEBSOCKET_PATH", "hooks", diff --git a/src/reactpy_django/exceptions.py b/src/reactpy_django/exceptions.py new file mode 100644 index 00000000..072f1d4f --- /dev/null +++ b/src/reactpy_django/exceptions.py @@ -0,0 +1,6 @@ +class ComponentParamError(TypeError): + ... + + +class ComponentDoesNotExistError(AttributeError): + ... diff --git a/src/reactpy_django/hooks.py b/src/reactpy_django/hooks.py index 00e22bd9..e9f80908 100644 --- a/src/reactpy_django/hooks.py +++ b/src/reactpy_django/hooks.py @@ -157,9 +157,7 @@ async def execute_query() -> None: set_data(None) set_loading(False) set_error(e) - _logger.exception( - f"Failed to execute query: {generate_obj_name(query) or query}" - ) + _logger.exception(f"Failed to execute query: {generate_obj_name(query)}") return # Query was successful @@ -252,7 +250,7 @@ async def execute_mutation(exec_args, exec_kwargs) -> None: set_loading(False) set_error(e) _logger.exception( - f"Failed to execute mutation: {generate_obj_name(mutation) or mutation}" + f"Failed to execute mutation: {generate_obj_name(mutation)}" ) # Mutation was successful diff --git a/src/reactpy_django/templates/reactpy/component.html b/src/reactpy_django/templates/reactpy/component.html index 08ab566d..7dae08eb 100644 --- a/src/reactpy_django/templates/reactpy/component.html +++ b/src/reactpy_django/templates/reactpy/component.html @@ -1,4 +1,9 @@ {% load static %} +{% if reactpy_failure %} +{% if reactpy_debug_mode %} +{% firstof reactpy_error "UnknownError" %}: "{% firstof reactpy_dotted_path "UnknownPath" %}" +{% endif %} +{% else %}
+{% endif %} diff --git a/src/reactpy_django/templatetags/reactpy.py b/src/reactpy_django/templatetags/reactpy.py index b508d0e9..d1ce87e5 100644 --- a/src/reactpy_django/templatetags/reactpy.py +++ b/src/reactpy_django/templatetags/reactpy.py @@ -1,3 +1,4 @@ +from logging import getLogger from uuid import uuid4 import dill as pickle @@ -7,15 +8,22 @@ from reactpy_django import models from reactpy_django.config import ( REACTPY_DATABASE, + REACTPY_DEBUG_MODE, REACTPY_RECONNECT_MAX, REACTPY_WEBSOCKET_URL, ) +from reactpy_django.exceptions import ComponentDoesNotExistError, ComponentParamError from reactpy_django.types import ComponentParamData -from reactpy_django.utils import _register_component, func_has_params +from reactpy_django.utils import ( + _register_component, + check_component_args, + func_has_args, +) REACTPY_WEB_MODULES_URL = reverse("reactpy:web_modules", args=["x"])[:-1][1:] register = template.Library() +_logger = getLogger(__name__) @register.inclusion_tag("reactpy/component.html") @@ -39,24 +47,45 @@ def component(dotted_path: str, *args, **kwargs):