Skip to content
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

v2.9.1: artisan ide-helper:models stopped working after update #1188

Closed
AlexeyKosov opened this issue Mar 18, 2021 · 16 comments · Fixed by #1196
Closed

v2.9.1: artisan ide-helper:models stopped working after update #1188

AlexeyKosov opened this issue Mar 18, 2021 · 16 comments · Fixed by #1196
Labels

Comments

@AlexeyKosov
Copy link

AlexeyKosov commented Mar 18, 2021

Versions:

  • ide-helper Version: 2.9.1
  • Laravel Version: 8.33.1
  • PHP Version: 7.4.15

Description:

> @php artisan ide-helper:models -N
Exception: Class 'Database\Factories\PaypalNotificationFactory' not found
Could not analyze class App\Models\PaypalNotification.

Trace:
#0 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/HasFactory.php(15): Illuminate\Database\Eloquent\Factories\Factory::factoryForModel('App\\Models\\Payp...')
#1 /var/www/vendor/barryvdh/laravel-ide-helper/src/Console/ModelsCommand.php(1096): App\Models\PaypalNotification::factory()
#2 /var/www/vendor/barryvdh/laravel-ide-helper/src/Console/ModelsCommand.php(281): Barryvdh\LaravelIdeHelper\Console\ModelsCommand->getFactoryMethods(Object(App\Models\PaypalNotification))
#3 /var/www/vendor/barryvdh/laravel-ide-helper/src/Console/ModelsCommand.php(162): Barryvdh\LaravelIdeHelper\Console\ModelsCommand->generateDocs(Array, Array)
#4 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Barryvdh\LaravelIdeHelper\Console\ModelsCommand->handle()
#5 /var/www/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#6 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#7 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#8 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(611): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#9 /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call(Array)
#10 /var/www/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#11 /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#12 /var/www/vendor/symfony/console/Application.php(971): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/vendor/symfony/console/Application.php(290): Symfony\Component\Console\Application->doRunCommand(Object(Barryvdh\LaravelIdeHelper\Console\ModelsCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/vendor/symfony/console/Application.php(166): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 {main}

Upd.
Solution:
Be sure to remove any use HasFactory; on models not having factories to avoid crashes in ide-helper

@AlexeyKosov
Copy link
Author

Figured. It was because the model contained use HasFactory; but in fact, there was no factory.
However, it worked fine in v2.9.0

@mfn
Copy link
Collaborator

mfn commented Mar 18, 2021

Looking at https://github.com/barryvdh/laravel-ide-helper/releases/tag/v2.9.1 , seems it this one:

@Im-Fran
Copy link

Im-Fran commented Mar 21, 2021

I'm having this problem too. I had to downgrade to v2.9.0 to fix it.

@alturic
Copy link

alturic commented Mar 23, 2021

Can confirm 2.9.1 introduced this. Seems to be a pretty major BC, no?

@mfn
Copy link
Collaborator

mfn commented Mar 23, 2021

Can anyone experiencing this issue bisect which change it really was? I don't use that feature myself so can't debug 🤷‍♀️

also re-opening: it seems OP meant his fix was to downgrade (which I wouldn't consider a fix)

@mfn mfn reopened this Mar 23, 2021
@mfn
Copy link
Collaborator

mfn commented Mar 23, 2021

Also pinging @ahmed-aliraqi maybe has an idea if it's related to your PR?

@AlexeyKosov
Copy link
Author

Can anyone experiencing this issue bisect which change it really was? I don't use that feature myself so can't debug 🤷‍♀️

also re-opening: it seems OP meant his fix was to downgrade (which I wouldn't consider a fix)

No, the fix was to remove use HasFactory; from models that did not actually have factories.

@alturic
Copy link

alturic commented Mar 23, 2021

Can anyone experiencing this issue bisect which change it really was? I don't use that feature myself so can't debug 🤷‍♀️
also re-opening: it seems OP meant his fix was to downgrade (which I wouldn't consider a fix)

No, the fix was to remove use HasFactory; from models that did not actually have factories.

Well, to be fair, downgrading to 2.9.0 (since 2.9.1 has #1074) or removing HasFactory "fixes" it. Ha.

@mfn mfn pinned this issue Mar 23, 2021
@mfn mfn changed the title artisan ide-helper:models stopped working after update to v2.9.1 v2.9.1: artisan ide-helper:models stopped working after update Mar 23, 2021
@mfn
Copy link
Collaborator

mfn commented Mar 23, 2021

I added this line to the release, does it sound technically correct? https://github.com/barryvdh/laravel-ide-helper/releases/tag/v2.9.1

Be sure to remove any use HasFactory; on models not having factories to avoid crashes in ide-helper

Not sure if we should do more here (upgrading guide for this single thing? 🤔)

I've pinned the issue and edited the title slightly to make it quickly discoverable 🤞

@alturic
Copy link

alturic commented Mar 23, 2021

I mean... it makes sense (because it's needed obviously ha), but it seems... strange to have to remove something included by default in every single model that artisan would make. Wouldn't a better approach be to just fail gracefully if there's no actual factory for the model, if that's possible?

Hell, at that point I'd even be willing to say the artisan command shouldn't even include the HasFactory if you didn't pass the factory creation flag but that's another point.

@mfn
Copy link
Collaborator

mfn commented Mar 23, 2021

Good points.

I really don't have any experience with this feature, so if someone wants to propose a more graceful handling, by all means please suggest a PR!

@barryvdh
Copy link
Owner

So can we revert the PR?

@mfn
Copy link
Collaborator

mfn commented Mar 23, 2021

The way I understand it, the change points out broken constellations but is by itself technically correct.

@barryvdh
Copy link
Owner

Yeah maybe we should make the error less intimidating though.

@alturic
Copy link

alturic commented Mar 23, 2021

I think a bit better documentation or a flag in ide-helper.php would be a solid solution. For example, I would honestly have thought include_factory_builders true/false would have been a flag that would have anything to do with factories. Now, I see that it says that is deprecated for Laravel 8, but still.

I suppose the biggest hangup for me is how something that's default (HasFactory) in Laravel/Artisan needing to be removed for every single model that doesn't have factories, to me, makes it seem like the PR is a BC. Is it sad I've literally thought to myself "well, instead of removing all of these HasFactory traits all the time, I'll just pass the -f flag when creating models"? Ha.

Keep up the amazing work on this package, I literally wouldn't use Laravel without it. :P

@ahmed-aliraqi
Copy link
Contributor

I created a new PR. to avoid this exception. #1196 @mfn @barryvdh

@mfn mfn closed this as completed in #1196 Apr 1, 2021
@mfn mfn unpinned this issue Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants