Switch upload_protocol esptool/espota in pythonscript

Hi, I have been experimenting with upload_protocol in the platformio.ini lately.
And noticed that I can remove upload_protocol completely.

platformio automagically choose esptool + “aut detect” if if upload_port is blank

upload_port =

And platformio choose espota if it detects an ip as upload_port.

upload_port = 10.199.1.62

So far so good.
But when i involve a pythonscript I get another behavior.

pythonscript:

Import("env")
env["UPLOAD_PORT"] = "10.199.1.62"

This does not work until i specify “upload_protocol = espota” in platformio.ini.

with upload_protocol still removed from platfomrio.ini:
pythonscript:

Import("env")
env["UPLOAD_PROTOCOL"] = "espota"
env["UPLOAD_PORT"] = "10.199.1.62"

i got this result:

Checking size .pio\build\esp32-poe-iso\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  16.8% (used 55160 bytes from 327680 bytes)
Flash: [=======   ]  67.7% (used 886761 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = espota      <<------!
Looking for upload port...
Using manually specified: 10.199.1.62
Uploading .pio\build\esp32-poe-iso\firmware.bin
esptool.py v4.5.1  <<-------!
Serial port 10.199.1.62

something is accepting >> env["UPLOAD_PROTOCOL"] = "espota" << but ignores it and choose esptool anyway.

I dont get this.
Help is highly appreciated

ok … I fixed the problem by using the prefix “pre:” in front of the file name.

extra_scripts = pre:platformio_upload.py

Everything works great now!