Skip to content

[FR] Increase character count for external Links as Attachments (currently 200 chars only) #9106

Description

@simonkuehling

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:

Image

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?

class InvenTreeURLField(models.URLField):
"""Custom URL field which has custom scheme validators."""
default_validators = [AllowedURLValidator()]
def __init__(self, **kwargs):
"""Initialization method for InvenTreeURLField."""
# Max length for InvenTreeURLField is set to 200
kwargs['max_length'] = 200
super().__init__(**kwargs)

Describe alternatives you've considered

One could use a url shortener as a whacky workaround, but that does not feel like a good one...

Examples of other systems

No response

Do you want to develop this?

  • I want to develop this.

Activity

  1. added
    enhancement
    triage:not-checked
    on Feb 19, 2025
  2. removed
    triage:not-checked
    on Feb 19, 2025
  3. matmair commented on Feb 19, 2025

    @matmair
    Member

    I think there is nothing against this proposal from a security view, should be fine

  4. SchrodingersGat commented on Feb 20, 2025

    @SchrodingersGat
    Member

    @simonkuehling I agree that this would be a good improvement. Do you want to tackle this one?

  5. simonkuehling commented on Feb 20, 2025

    @simonkuehling
    ContributorAuthor

    @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)

  6. matmair commented on Feb 20, 2025

    @matmair
    Member

    is you venv enabled? does not read like it

  7. SchrodingersGat commented on Feb 20, 2025

    @SchrodingersGat
    Member

    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 update
  8. simonkuehling commented on Feb 21, 2025

    @simonkuehling
    ContributorAuthor

    Yes, as far as I can tell the venv is enabled - even manually activating it again does not help - I'm a little confused

    (venv) vscode ➜ /home/inventree (master) $ echo $VIRTUAL_ENV
    /workspaces/InvenTree/dev/venv
    (venv) vscode ➜ /home/inventree (master) $ invoke
    bash: /home/inventree//dev/venv/bin/invoke: cannot execute: required file not found
    (venv) vscode ➜ /home/inventree (master) $ . ./dev/venv/bin/activate
    (venv) (venv) vscode ➜ /home/inventree (master) $ invoke update
    bash: /home/inventree//dev/venv/bin/invoke: cannot execute: required file not found
    

    looking into invoke I get:

    #!/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...

  9. SchrodingersGat commented on Feb 21, 2025

    @SchrodingersGat
    Member

    @simonkuehling have you run invoke update first? This is required to get all the necessary python packages installed into the devcontainer.

  10. simonkuehling commented on Feb 21, 2025

    @simonkuehling
    ContributorAuthor

    @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?

  11. SchrodingersGat commented on Feb 21, 2025

    @SchrodingersGat
    Member

    @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).

  12. SchrodingersGat commented on Feb 21, 2025

    @SchrodingersGat
    Member

    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

  13. simonkuehling commented on Feb 21, 2025

    @simonkuehling
    ContributorAuthor

    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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions