Skip to content

Internal error: Call to a member function dispatch() on null #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mvhirsch opened this issue Feb 6, 2023 · 5 comments
Closed

Internal error: Call to a member function dispatch() on null #425

mvhirsch opened this issue Feb 6, 2023 · 5 comments

Comments

@mvhirsch
Copy link
Contributor

mvhirsch commented Feb 6, 2023

I'm running into a similar issue - same conclusion. It's broken since v1.3.29 and my wild guess would be this commit 4490e56

Here's my stack trace:

 Internal error: Internal error: Call to a member function dispatch() on null in file /path/to/project/src/VideoBundle/Command/FixSegmentsCompleteCommand.php                                                           
                                                                                                                                                                                                                                     
 Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:                                                                                                                             
 #0 /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Query/AST/IndexBy.php(51): PHPStan\Type\Doctrine\Query\QueryResultTypeWalker->walkIndexBy()                                                                   
 #1 /path/to/project/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/QueryResultTypeWalker.php(316): Doctrine\ORM\Query\AST\IndexBy->dispatch()                                                                 
 #2 /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php(65): PHPStan\Type\Doctrine\Query\QueryResultTypeWalker->walkIdentificationVariableDeclaration()               
 #3 /path/to/project/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/QueryResultTypeWalker.php(304): Doctrine\ORM\Query\AST\IdentificationVariableDeclaration->dispatch()                                       
 #4 /path/to/project/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/QueryResultTypeWalker.php(180): PHPStan\Type\Doctrine\Query\QueryResultTypeWalker->walkFromClause()                                        
 #5 /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php(42): PHPStan\Type\Doctrine\Query\QueryResultTypeWalker->walkSelectStatement()                                             
 #6 /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php(288): Doctrine\ORM\Query\Exec\SingleSelectExecutor->__construct()                                                                         
 #7 /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(411): Doctrine\ORM\Query\SqlWalker->getExecutor()                                                                                            
 #8 /path/to/project/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/QueryResultTypeWalker.php(119): Doctrine\ORM\Query\Parser->parse()                                                                         
 #9 /path/to/project/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/QueryBuilder/QueryBuilderGetQueryDynamicReturnTypeExtension.php(163): PHPStan\Type\Doctrine\Query\QueryResultTypeWalker::walk()                  
 #10 /path/to/project/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/QueryBuilder/QueryBuilderGetQueryDynamicReturnTypeExtension.php(146):                                                                           
 PHPStan\Type\Doctrine\QueryBuilder\QueryBuilderGetQueryDynamicReturnTypeExtension->getQueryType()                                                                                                                                   
 #11 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3353): PHPStan\Type\Doctrine\QueryBuilder\QueryBuilderGetQueryDynamicReturnTypeExtension->getTypeFromMethodCall()       
 #12 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1365): PHPStan\Analyser\MutatingScope->methodCallReturnType()                                                           
 #13 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1371): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()                                                     
 #14 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(557): PHPStan\Analyser\MutatingScope->resolveType()                                                                     
 #15 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1365): PHPStan\Analyser\MutatingScope->getType()                                                                        
 #16 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1371): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()                                                     
 #17 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(557): PHPStan\Analyser\MutatingScope->resolveType()                                                                     
 #18 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(777): PHPStan\Analyser\MutatingScope->getType()                                                                         
 #19 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(557): PHPStan\Analyser\MutatingScope->resolveType()                                                                     
 #20 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1446): PHPStan\Analyser\MutatingScope->getType()                                                                    
 #21 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(557): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr()                                                
 #22 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                         
 #23 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(521): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                        
 #24 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                         
 #25 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(599): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                        
 #26 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                         
 #27 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(571): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                        
 #28 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(327): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                         
 #29 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes()                                                                 
 #30 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(148): PHPStan\Analyser\FileAnalyser->analyseFile()                                                                       
 #31 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}()                         
 #32 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_4dd92cd93\Evenement\EventEmitter->emit()                                                       
 #33 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_4dd92cd93\Clue\React\NDJson\Decoder->handleData()                         
 #34 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_4dd92cd93\Evenement\EventEmitter->emit()                                                                
 #35 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_4dd92cd93\React\Stream\Util::_PHPStan_4dd92cd93\React\Stream\{closure}()  
 #36 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_4dd92cd93\Evenement\EventEmitter->emit()                                               
 #37 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_4dd92cd93\React\Stream\DuplexResourceStream->handleData()                              
 #38 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_4dd92cd93\React\EventLoop\StreamSelectLoop->waitForStreamActivity()                    
 #39 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(108): _PHPStan_4dd92cd93\React\EventLoop\StreamSelectLoop->run()                                                         
 #40 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()                                                              
 #41 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_4dd92cd93\Symfony\Component\Console\Command\Command->run()                                       
 #42 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_4dd92cd93\Symfony\Component\Console\Application->doRunCommand()                                  
 #43 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_4dd92cd93\Symfony\Component\Console\Application->doRun()                                         
 #44 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_4dd92cd93\Symfony\Component\Console\Application->run()                                                                      
 #45 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_4dd92cd93\{closure}()                                                                                                       
 #46 /path/to/project/vendor/phpstan/phpstan/phpstan(7): require('phar:///home/me...')                                                                                                                                  
 #47 /path/to/project/vendor/bin/phpstan(115): include('/home/meh/proje...')                                                                                                                                            
 #48 {main}                                                                                                                                                                                                                          
 Child process error (exit code 1):

my dynamic query:

$qb = $this->em->createQueryBuilder()
    ->select('episode.id')
    ->from('VideoBundle:Episode', 'episode', 'episode.id')
    ->where('episode.segmentsComplete = false')
    ->andWhere('0 != SIZE(episode.segments)')
    ->andWhere(
        '0 < (SELECT COUNT(last_segment.id) FROM VideoBundle:Segment as last_segment
              WHERE last_segment.episode = episode.id AND last_segment.isLastSegment = true)'
    )
    ->andWhere(
        "0 = (SELECT COUNT(segment.id) FROM VideoBundle:Segment as segment
              WHERE segment.episode = episode.id AND segment.state != 'distributed')"
    )
;
class Episode
{
    /**
     * @var Collection<Segment>
     * @ORM\OneToMany(
     *      targetEntity="App\VideoBundle\Entity\Segment",
     *      mappedBy="episode",
     *      cascade={"persist", "remove"},
     *      orphanRemoval=true
     * )
     * @ORM\OrderBy({"position" = "ASC"})
     */
    private $segments;
}
class Segment
{
/**
     * @ORM\ManyToOne(
     *     targetEntity="App\VideoBundle\Entity\Episode",
     *     inversedBy="segments",
     *     cascade={"persist"}
     * )
     * @ORM\JoinColumn(name="episode_id", referencedColumnName="id", nullable=false)
     * @var Episode
     */
    private $episode;
}

Originally posted by @mvhirsch in #422 (comment)

ondrejmirtes added a commit that referenced this issue Feb 6, 2023
@ondrejmirtes
Copy link
Member

Please provide a more complete example. The entities do not contain all the data. I tried to reproduce your problem, but couldn't: 148fd32

The type inference currently returns "mixed" because the DQL is surely wrong, there are missing columns. Maybe if you add more columns to the entities, it's gonna crash with a fatal error. I'd be fine with a PR that shows the crash.

@mvhirsch
Copy link
Contributor Author

mvhirsch commented Feb 6, 2023

I'll provide more details at the end of this week!

@mvhirsch
Copy link
Contributor Author

Sorry for late reply.

I tried reproducing my issue in #429, but I can't.
After a bit trial-and-error I realized: the code doesn't need to indexBy (third argument on select()).

Probably the issue is a combination of using old doctrine related libs (I'm currently forced to use):

symfony composer info doctrine/*
doctrine/annotations                1.14.2  Docblock Annotations Parser
doctrine/cache                      1.13.0  PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                1.8.0   PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     2.13.3  PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, persistence interfaces, proxies, ev...
doctrine/data-fixtures              1.5.4   Data Fixtures for all Doctrine Object Managers
doctrine/dbal                       2.13.9  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations               v1.0.0  A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/doctrine-bundle            1.12.13 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle      1.4.0   Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle   3.4.2   Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle v1.3.2  Symfony DoctrineMigrationsBundle
doctrine/event-manager              1.2.0   The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  1.4.4   PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator               1.5.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      1.2.3   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 v1.8.1  Database Schema migrations using Doctrine DBAL
doctrine/orm                        2.7.5   Object-Relational-Mapper for PHP
doctrine/persistence                1.3.8   The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/reflection                 1.2.3   The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional functionality on top of the reflection functionality that comes with PHP...

I'm very sorry for stealing your time. I think this can be closed. Would you mind to remove the added files? Or should I?

@ondrejmirtes
Copy link
Member

No problem, thanks.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants