If you already have an instance named foo, trying to created another one with the same name will not immediately fail if the source is not cached.
Steps to reproduce:
$ fingerprint="$(lxc image list -f csv -c lf ubuntu-daily:24.04 type=container | head -n1 | cut -d, -f2)"
$ lxc init "ubuntu-daily:$fingerprint" foo # create instance and populate local image cache
Creating foo
$ lxc init "ubuntu-daily:$fingerprint" foo # fail early, good
Creating foo
Error: Failed creating instance record: Add instance info to the database: This "instances" entry already exists
$ lxc image delete "local:$fingerprint" # remove the locally cached image
$ lxc init "ubuntu-daily:$fingerprint" foo # fails late after retrieving the image
Creating foo
Retrieving image: metadata: 100% (1.21GB/s)
Retrieving image: rootfs: 1% (2.86MB/s)
...
Error: Failed creating instance record: Add instance info to the database: This "instances" entry already exists
Ideally, the check for duplicated name should be done prior to doing the expensive image fetch.