Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/inventree/InvenTree
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair committed Oct 16, 2023
2 parents 9cb8f60 + d98b1bb commit 4216287
Show file tree
Hide file tree
Showing 111 changed files with 51,270 additions and 44,168 deletions.
7 changes: 5 additions & 2 deletions docs/docs/start/docker_prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The example docker compose file launches the following containers:
| --- | --- |
| inventree-db | PostgreSQL database |
| inventree-server | Gunicorn web server |
| invenrtee-worker | django-q background worker |
| inventree-worker | django-q background worker |
| inventree-proxy | nginx proxy server |
| *inventree-cache* | *redis cache (optional)* |

Expand Down Expand Up @@ -91,7 +91,7 @@ This container uses the official [redis image](https://hub.docker.com/_/redis).

!!! info "Redis on Docker"
Docker adds an additional network layer - that might lead to lower performance than bare metal.
To optimise and configure your redis deployment follow the [official docker guide](https://redis.io/docs/getting-started/install-stack/docker/#configuration).
To optimize and configure your redis deployment follow the [official docker guide](https://redis.io/docs/getting-started/install-stack/docker/#configuration).

!!! warning "Disabled by default"
The *redis* container is not enabled in the default configuration. This is provided as an example for users wishing to use redis.
Expand Down Expand Up @@ -205,6 +205,9 @@ docker compose pull

This ensures that the InvenTree containers will be running the latest version of the InvenTree source code.

!!! tip "Docker Directory"
All `docker compose` commands must be performed in the same directory as the [docker-compose.yml file](#required-files)

!!! info "Tagged Version"
If you are targeting a particular "tagged" version of InvenTree, you may wish to edit the `INVENTREE_TAG` variable in the `.env` file before issuing the `docker compose pull` command

Expand Down
13 changes: 8 additions & 5 deletions src/backend/InvenTree/InvenTree/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ def convert_physical_value(value: str, unit: str = None, strip_units=True):
# If the value is specified strangely (e.g. as a fraction or a dozen), this can cause issues
# So, we ensure that it is converted to a floating point value
# If we wish to return a "raw" value, some trickery is required
if unit:
magnitude = ureg.Quantity(value.to(ureg.Unit(unit))).magnitude
else:
magnitude = ureg.Quantity(value.to_base_units()).magnitude
try:
if unit:
magnitude = ureg.Quantity(value.to(ureg.Unit(unit))).magnitude
else:
magnitude = ureg.Quantity(value.to_base_units()).magnitude

magnitude = float(ureg.Quantity(magnitude).to_base_units().magnitude)
magnitude = float(ureg.Quantity(magnitude).to_base_units().magnitude)
except Exception as exc:
raise ValidationError(_(f'Invalid quantity supplied ({exc})'))

if strip_units:
return magnitude
Expand Down
12 changes: 10 additions & 2 deletions src/backend/InvenTree/InvenTree/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

from InvenTree.version import INVENTREE_SW_VERSION
import InvenTree.version

logger = logging.getLogger('inventree')

Expand All @@ -31,6 +31,7 @@ def sentry_ignore_errors():
Http404,
ValidationError,
rest_framework.exceptions.AuthenticationFailed,
rest_framework.exceptions.NotAuthenticated,
rest_framework.exceptions.PermissionDenied,
rest_framework.exceptions.ValidationError,
]
Expand All @@ -47,12 +48,19 @@ def init_sentry(dsn, sample_rate, tags):
traces_sample_rate=sample_rate,
send_default_pii=True,
ignore_errors=sentry_ignore_errors(),
release=INVENTREE_SW_VERSION,
release=InvenTree.version.INVENTREE_SW_VERSION,
environment='development' if InvenTree.version.isInvenTreeDevelopmentVersion() else 'production'
)

for key, val in tags.items():
sentry_sdk.set_tag(f'inventree_{key}', val)

sentry_sdk.set_tag('api', InvenTree.version.inventreeApiVersion())
sentry_sdk.set_tag('platform', InvenTree.version.inventreePlatform())
sentry_sdk.set_tag('git_branch', InvenTree.version.inventreeBranch())
sentry_sdk.set_tag('git_commit', InvenTree.version.inventreeCommitHash())
sentry_sdk.set_tag('git_date', InvenTree.version.inventreeCommitDate())


def report_exception(exc):
"""Report an exception to sentry.io"""
Expand Down
4 changes: 2 additions & 2 deletions src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@

# Cross Origin Resource Sharing (CORS) options

# Only allow CORS access to API
CORS_URLS_REGEX = r'^/api/.*$'
# Only allow CORS access to API and media endpoints
CORS_URLS_REGEX = r'^/(api|media|static)/.*$'

# Extract CORS options from configuration file
CORS_ORIGIN_ALLOW_ALL = get_boolean_setting(
Expand Down
15 changes: 15 additions & 0 deletions src/backend/InvenTree/InvenTree/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ def test_dimensionless_units(self):
q = InvenTree.conversion.convert_physical_value(val)
self.assertAlmostEqual(q, expected, 3)

def test_invalid_units(self):
"""Test conversion with bad units"""

tests = {
'3': '10',
'13': '-?-',
'-3': 'xyz',
'-12': '-12',
'1/0': '1/0',
}

for val, unit in tests.items():
with self.assertRaises(ValidationError):
InvenTree.conversion.convert_physical_value(val, unit)

def test_invalid_values(self):
"""Test conversion of invalid inputs"""

Expand Down
Loading

0 comments on commit 4216287

Please sign in to comment.