Closed Richard87 closed 3 years ago
Very strange, I hacked around the problem above by fetching the id from my office, and then requesting the object directly.
But, just know the bug resurfaced anyway:
GET http://localhost:8000/api/office_nefles/5
@context | "/api/contexts/OfficeNefle"
@id | "/api/office_nefles/5"
@type | "OfficeNefle"
id | 5
domain | "test.example.com"
extraDomains | []
siteConfig | {…}
And as you can see in the screenshot, the field generatedAt is null
, probably because the SQL query ommits those columns.
GET http://localhost:8000/api/office_nefles/5
I have also tripple checked the Groups and that the getters are public (setters are private)
I'm completley stumped, would love some ideas on how to troubleshoot!
Database view (for complete-ness!)
Hmm, it seems the DQL generated by ItemDataProvider SELECT o FROM App\Entity\Office\Nefle o WHERE o.id = :id_id
is absolutley correct....
So strange, running the query in a command, everything works as expected:
class TestCommand extends Command
{
public function __construct(
public EntityManagerInterface $em,
public SerializerInterface $serializer,
)
{
parent::__construct('app:test:test');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$query = $this->em->createQuery("SELECT o FROM App\Entity\Office\Nefle o WHERE o.id = :id_id");
$query->setParameter(":id_id", 5);
$results = $query->getOneOrNullResult();
$json = $this->serializer->serialize($results,"jsonld", ["groups"=> ["OfficeNefle:view"]]);
dump($json);
return Command::SUCCESS;
}
}
The problem all along was outdated cache, specifically a missconfiguration of doctrine.query_cache_driver
that had stored an old version of the DQL => SQL conversion
API Platform version(s) affected: 2.6.5
Description
A request to GET a resource via subresource is missing a lot of information. Retrieving the same resource by its direct IRI works as expected.
In other words, the generated SQL is only including a few of the required columns, not all columns. The context groups are correct and works as expected if the getters return dummy data...
This works perfectly:
This fails:
(extraDinaubs abd siteConfig returns [] when its null)
The generated SQL explains why the data is missing:
And maybe the stack trace will help you more than it helped me...
Else I'm using these related versions: