You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FR] Increase character count for external Links as Attachments (currently 200 chars only) #9106
Please verify that this feature request has NOT been suggested before.
I checked and didn't find a similar feature request
Problem statement
In purchase orders, we always add a shipment tracking link in the Attachments panel if we get one from a supplier - so that all information about the purchase order is always in one single spot, accessible for every team member.
We regularly run into the issue that tracking links by DHL etc. are quite a bit longer in character count than the allowed 200 chars:
Suggested solution
I would suggest to increase the max length of this field to maybe 2000 characters (like it is set in some other URL instances in supplier part links etc), to account for these long URLs.
I guess there is a migration needed to overwrite the default max_length from the model defined here, right?
@SchrodingersGat I would like to - but failed so far unfortunately... Maybe you have a hint for me with this?
I am working in vscode running the devcontainer, I edited the file in question (as noted above) and tried to generate the necessary migration like this which failed:
vscode ➜ /home/inventree (master) $ python ./src/backend/InvenTree/manage.py makemigrations
Traceback (most recent call last):
File "/home/inventree/./src/backend/InvenTree/manage.py", line 13, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/inventree/./src/backend/InvenTree/manage.py", line 24, in <module>
main()
File "/home/inventree/./src/backend/InvenTree/manage.py", line 15, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Seems like the devcontainer does not have the python requirements installed correctly, maybe? Am I missing something here?
(same for pip, invoke etc)
#!/workspaces/InvenTree/dev/venv/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from invoke.main import program
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(program.run())
that shebang line might give a hint as there is no /workspaces/... path in my devcontainer...?
(venv) vscode ➜ /home/inventree (master) $ cd /workspaces
bash: cd: /workspaces: No such file or directory
EDIT: I have missed that the echo $VIRTUAL_ENV already also points to the same path under /workspaces/... (which does not exist) - so, true, the venv does not load correctly it seems...
@SchrodingersGat whatever has been stuck - a reboot and full container rebuild fixed it...
back to the actual topic: makemigrations does not pick up the changed max_length parameter automatically:
(venv) vscode ➜ /home/inventree (master) $ python ./src/backend/InvenTree/manage.py makemigrations
Python version 3.11.2 - /home/inventree/dev/venv/bin/python
/home/inventree/dev/venv/lib/python3.11/site-packages/allauth/exceptions.py:9: UserWarning: allauth.exceptions is deprecated, use allauth.core.exceptions
warnings.warn("allauth.exceptions is deprecated, use allauth.core.exceptions")
No changes detected
Do I need to craft a manual migration to change all appearances of InvenTreeURLField with explicitly set max_length-parameter then?
@simonkuehling I seem to remember trying to look into this before, and (for some reason) the URL field default length proves hard to override. Maybe a manual migration would fix it - although it does leave us open to potential issues down the line (if we add or adjust more URL fields).
Ok, it might be due to the database backend you are using when you run the "makemigrations" code - only some DB backends actually enforce a character limit.
Why is Django Not Detecting the Change?
Django does not track max_length for databases that do not enforce it strictly.
PostgreSQL treats VARCHAR(n) as equivalent to TEXT, meaning changing max_length has no practical effect at the database level.
Django's migration detection logic skips certain changes that do not affect schema behavior.
MySQL, MariaDB, and Oracle will detect changes to max_length because they impose strict limits on VARCHAR(n).
Source: a popular online AI tool
So, if you setup a MySQL database backend on your local instance, and then run makemigrations - it should detect the changes and generate the migrations. Then, you can commit those - and any DB backend which does not support the change will ignore it and all will be well
oh well, that was a rabbit hole... turns out that django indeed silently omits changes to the max_length configuration, despite the database actually not using a text columns but a length-limites character varying type. Even manually crafting a migration, it simply does not generate an ALTER COLUMN query when executing the migration.
I found a workaround, though: we can change the link fields to a textField in a first migration, and then put another migration directly afterwards that reverts back to a InvenTreeURLField which now respects the max_length parameter because it is forced to alter the column type...
I'm cleaning up and will provide a PR for review in a bit...
Activity
matmair commentedon Feb 19, 2025
I think there is nothing against this proposal from a security view, should be fine
SchrodingersGat commentedon Feb 20, 2025
@simonkuehling I agree that this would be a good improvement. Do you want to tackle this one?
simonkuehling commentedon Feb 20, 2025
@SchrodingersGat I would like to - but failed so far unfortunately... Maybe you have a hint for me with this?
I am working in vscode running the devcontainer, I edited the file in question (as noted above) and tried to generate the necessary migration like this which failed:
Seems like the devcontainer does not have the python requirements installed correctly, maybe? Am I missing something here?
(same for
pip,invokeetc)matmair commentedon Feb 20, 2025
is you venv enabled? does not read like it
SchrodingersGat commentedon Feb 20, 2025
Within the devcontainer there should be a virtual environment setup in
./dev/venv/- which should be automatically activated.I would suggest the following steps:
. ./dev/venv/bin/activate invoke updatesimonkuehling commentedon Feb 21, 2025
Yes, as far as I can tell the venv is enabled - even manually activating it again does not help - I'm a little confused
looking into
invokeI get:that shebang line might give a hint as there is no
/workspaces/...path in my devcontainer...?EDIT: I have missed that the
echo $VIRTUAL_ENValready also points to the same path under/workspaces/...(which does not exist) - so, true, the venv does not load correctly it seems...SchrodingersGat commentedon Feb 21, 2025
@simonkuehling have you run
invoke updatefirst? This is required to get all the necessary python packages installed into the devcontainer.simonkuehling commentedon Feb 21, 2025
@SchrodingersGat whatever has been stuck - a reboot and full container rebuild fixed it...
back to the actual topic:
makemigrationsdoes not pick up the changedmax_lengthparameter automatically:Do I need to craft a manual migration to change all appearances of
InvenTreeURLFieldwith explicitly setmax_length-parameter then?SchrodingersGat commentedon Feb 21, 2025
@simonkuehling I seem to remember trying to look into this before, and (for some reason) the URL field default length proves hard to override. Maybe a manual migration would fix it - although it does leave us open to potential issues down the line (if we add or adjust more URL fields).
SchrodingersGat commentedon Feb 21, 2025
Ok, it might be due to the database backend you are using when you run the "makemigrations" code - only some DB backends actually enforce a character limit.
Source: a popular online AI tool
So, if you setup a MySQL database backend on your local instance, and then run
makemigrations- it should detect the changes and generate the migrations. Then, you can commit those - and any DB backend which does not support the change will ignore it and all will be wellsimonkuehling commentedon Feb 21, 2025
oh well, that was a rabbit hole... turns out that django indeed silently omits changes to the max_length configuration, despite the database actually not using a text columns but a length-limites
character varyingtype. Even manually crafting a migration, it simply does not generate anALTER COLUMNquery when executing the migration.I found a workaround, though: we can change the link fields to a
textFieldin a first migration, and then put another migration directly afterwards that reverts back to aInvenTreeURLFieldwhich now respects the max_length parameter because it is forced to alter the column type...I'm cleaning up and will provide a PR for review in a bit...