Use custom fields with the inline plugin

Hi,

I’d like to use the inline plugin with custom file tags.

I read How to use Custom Fields? regarding the use of custom tag parsing using plugins.
I managed to set it up, but I can’t seem to be able to access the custom field from item_fields.

Here is my setup:

$ beet --version
beets version 1.6.0
Python version 3.9.10
plugins: additionalfields, inline

~/.config/beets/config.yaml:

directory: ~/Music
pluginpath: ~/.config/beets/plugins
plugins:
    # Custom plugins
    - additionnalfields
    # Built-in plugins
    - inline
paths:
    default: Albums/$albumartist/$album%aunique{}/$disc_and_track $title
item_fields:
    disc_and_track: |
        if custom:
           return custom

        tracknum = f"{track:02}"

        if disctotal > 1:
            return f"{disc:1}-{tracknum}"

        return f"{tracknum}"

~/.config/beets/plugins/additionalfields.py:

from beets.plugins import BeetsPlugin
from mediafile import (
    MediaField,
    MP4StorageStyle,
    MP3DescStorageStyle,
    StorageStyle,
    ASFStorageStyle,
)


class AdditionalFields(BeetsPlugin):
    def __init__(self):
        super().__init__()

        field_name = "custom"
        self.add_media_field(
            field_name,
            MediaField(
                StorageStyle(field_name),
                MP3DescStorageStyle(field_name),
                MP4StorageStyle(f"----:com.apple.iTunes:{field_name.upper()}"),
                ASFStorageStyle(field_name),
            ),
        )
        self._log.debug(f"Added field {field_name}")

And here are the logs I’m getting when running beets import -vv:

user configuration: /Users/user/.config/beets/config.yaml
data directory: /Users/user/.config/beets
plugin paths: /Users/user/.config/beets/plugins
/Users/user/Library/Python/3.9/lib/python/site-packages/beets/mediafile.py:19: UserWarning: beets.mediafile is deprecated; use mediafile instead
  warnings.warn("beets.mediafile is deprecated; use mediafile instead")
additionalfields: Added field custom
inline: adding item field disc_and_track
Sending event: pluginload
library database: /Users/user/.config/beets/library.db
library directory: /Users/user/Music
Sending event: library_opened
Sending event: import_begin
⋮
beetsplug.inline.InlineError: error in inline path field code:
if custom:
   return custom

tracknum = f"{track:02}"

if disctotal > 1:
    return f"{disc:1}-{tracknum}"

return f"{tracknum}"

NameError: name 'custom' is not defined

Is there any way to make this work?