Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got EntityName since upgrade to 2.6.0 #5820

Closed
opened 2026-01-22 15:18:47 +01:00 by admin · 8 comments
Owner

Originally created by @allan-simon on GitHub (Dec 21, 2017).

I have the following builder request

          return $builder
              ->select('e')
              ->from('AppBundle:Event', 'e')
              ->addSelect('MIN(o.startTime) AS HIDDEN')
              ->leftJoin('e.occurences', 'o')
              ->where('o.startTime BETWEEN CURRENT_DATE() AND :date ')
              ->andWhere('e.published = true')
              ->andWhere('e.place = :place')
              ->groupBy('e.id')
              ->setMaxResults(10)
              ->setParameter(':date', $date)
              ->setParameter(':place', $place)
              ->getQuery()
              ->getResult()
          ;   

it used to work fine, but since upgrade to 2.6.0 I got the error

[Syntax Error] line 0, col 42: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got 'AppBundle:Event'

It seems to work if I add FROM like this :

              ->from(' FROM AppBundle:Event', 'e')

is it a known issue ? (or something wrong in my original code ?)

Originally created by @allan-simon on GitHub (Dec 21, 2017). I have the following builder request ``` return $builder ->select('e') ->from('AppBundle:Event', 'e') ->addSelect('MIN(o.startTime) AS HIDDEN') ->leftJoin('e.occurences', 'o') ->where('o.startTime BETWEEN CURRENT_DATE() AND :date ') ->andWhere('e.published = true') ->andWhere('e.place = :place') ->groupBy('e.id') ->setMaxResults(10) ->setParameter(':date', $date) ->setParameter(':place', $place) ->getQuery() ->getResult() ; ``` it used to work fine, but since upgrade to 2.6.0 I got the error ``` [Syntax Error] line 0, col 42: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got 'AppBundle:Event' ``` It seems to work if I add ` FROM` like this : ``` ->from(' FROM AppBundle:Event', 'e') ``` is it a known issue ? (or something wrong in my original code ?)
admin added the BugBC Break labels 2026-01-22 15:18:47 +01:00
admin closed this issue 2026-01-22 15:18:48 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 21, 2017):

What's the generated DQL string for that query builder?

@Ocramius commented on GitHub (Dec 21, 2017): What's the generated DQL string for that query builder?
Author
Owner

@allan-simon commented on GitHub (Dec 21, 2017):

how do i get it ?

@allan-simon commented on GitHub (Dec 21, 2017): how do i get it ?
Author
Owner

@Ocramius commented on GitHub (Dec 21, 2017):

Instead of ->getQuery() do a ->getDQL()

@Ocramius commented on GitHub (Dec 21, 2017): Instead of `->getQuery()` do a `->getDQL()`
Author
Owner

@Majkl578 commented on GitHub (Dec 21, 2017):

On master, QB generates following DQL:

SELECT e, MIN(o.startTime) AS HIDDEN FROM AppBundle:Event e LEFT JOIN e.occurences o WHERE (o.startTime BETWEEN CURRENT_DATE() AND :date ) AND e.published = true AND e.place = :place GROUP BY e.id

So there is obviously missing alias for MIN() function.

@Majkl578 commented on GitHub (Dec 21, 2017): On master, QB generates following DQL: ``` SELECT e, MIN(o.startTime) AS HIDDEN FROM AppBundle:Event e LEFT JOIN e.occurences o WHERE (o.startTime BETWEEN CURRENT_DATE() AND :date ) AND e.published = true AND e.place = :place GROUP BY e.id ``` So there is obviously missing alias for MIN() function.
Author
Owner

@Ocramius commented on GitHub (Dec 21, 2017):

"HIDDEN" is a reserved DQL keyword

On 21 Dec 2017 17:35, "Michael Moravec" notifications@github.com wrote:

On master, QB generates following DQL:

SELECT e, MIN(o.startTime) AS HIDDEN FROM AppBundle:Event e LEFT JOIN e.occurences o WHERE (o.startTime BETWEEN CURRENT_DATE() AND :date ) AND e.published = true AND e.place = :place GROUP BY e.id

So there is obviously missing alias for MIN() function.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6932#issuecomment-353396548,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakMI1jPG4A6MrbXMtaOrZSgPm1YZwks5tCojhgaJpZM4RJ-e3
.

@Ocramius commented on GitHub (Dec 21, 2017): "HIDDEN" is a reserved DQL keyword On 21 Dec 2017 17:35, "Michael Moravec" <notifications@github.com> wrote: > On master, QB generates following DQL: > > SELECT e, MIN(o.startTime) AS HIDDEN FROM AppBundle:Event e LEFT JOIN e.occurences o WHERE (o.startTime BETWEEN CURRENT_DATE() AND :date ) AND e.published = true AND e.place = :place GROUP BY e.id > > So there is obviously missing alias for MIN() function. > > — > You are receiving this because you commented. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/6932#issuecomment-353396548>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakMI1jPG4A6MrbXMtaOrZSgPm1YZwks5tCojhgaJpZM4RJ-e3> > . >
Author
Owner

@Majkl578 commented on GitHub (Dec 21, 2017):

"HIDDEN" is a reserved DQL keyword

Yes, but the query is valid according to 2.5 EBNF:

SelectExpression        ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable]

"AS HIDDEN" is fine and the alias should be optional as well (which sounds a bit strange though).

This is not a QueryBuilder bug which generates same DQL as on 2.5, but a parser bug.

LanguageRecognitionTest test case:

    public function testOmittingAliasVariableInSelectExpression() : void
    {
        $this->assertValidDQL('SELECT g, LENGTH(g.from) AS HIDDEN FROM ' . DQLKeywordsModelGroup::class . ' g');
    }

Works with 2.5, fails with 2.6.
Bisected to b7bd42638d so it's related to #6928.

@Majkl578 commented on GitHub (Dec 21, 2017): > "HIDDEN" is a reserved DQL keyword Yes, but the query is valid according to 2.5 EBNF: ``` SelectExpression ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable] ``` "AS HIDDEN" is fine and the alias should be optional as well (which sounds a bit strange though). This is not a QueryBuilder bug which generates same DQL as on 2.5, but a parser bug. LanguageRecognitionTest test case: ``` public function testOmittingAliasVariableInSelectExpression() : void { $this->assertValidDQL('SELECT g, LENGTH(g.from) AS HIDDEN FROM ' . DQLKeywordsModelGroup::class . ' g'); } ``` Works with 2.5, fails with 2.6. Bisected to b7bd42638dcf8aa049698f01466688ff7762953b so it's related to #6928.
Author
Owner

@stof commented on GitHub (Mar 7, 2018):

Not, the EBNF has [["AS"] ["HIDDEN"] AliasResultVariable]. so AS HIDDEN is not valid, as you miss the AliasResultVariable

@stof commented on GitHub (Mar 7, 2018): Not, the EBNF has ` [["AS"] ["HIDDEN"] AliasResultVariable]`. so `AS HIDDEN` is not valid, as you miss the `AliasResultVariable`
Author
Owner

@beberlei commented on GitHub (Dec 7, 2020):

Fixed by https://github.com/doctrine/orm/pull/7077

@beberlei commented on GitHub (Dec 7, 2020): Fixed by https://github.com/doctrine/orm/pull/7077
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5820