I think you're misinterpreting the code. I don't see in that code
snippet where it says that the 'alloc_cpus' field is empty but there's a
corresponding value in AllocCPU.
They way I read it, it's saying that if $job->{'alloc_cpus'} doesn't
exist, than Slurm is configured to count CPUs as a TRES, so look at the
TRES for a job and get the CPU count from there.
I think this behavior depends on the value of the SelectType parameter
in slurm.conf. Read the section of the slurm.conf documentation starting
at "SelectType".
https://slurm.schedmd.com/slurm.conf.html
Prentice