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
Using ModuleSpec syntax in RequiredModules causes incorrect "cyclic dependency" failures #2607
Comments
|
I have to say, the error message when trying to run a script which has a dependency, like $last = @();
foreach($module in mkdir Test1, Test2, Test3, Test4 -Force) {
New-ModuleManifest ($module.Name + "\" + $module.Name + ".psd1") -RequiredModules $last
$global:last += @{ ModuleName = $Module.Name; ModuleVersion = '1.0' }
}Note that only three of those actually have dependencies, and only 2 of them actually need to have ModuleSpec to cause the problem. Given a script #requires -modules Test4
Get-Module Test*Running it produces a completely unhelpful error (and two entries in |
|
I can confirm the issue. I have the following setup:
Note that if I leave only 1 dependency in the manifest files it works fine. |
|
This breaks some production PowerShellGet module dependency traversal scenarios and is definitely needed for |
This fixes issue #2607. 'RequiredModules' is a field in module manifest that can reference other modules using ModuleSpecification format. The basic version of this format (just module name) was working fine, however, there was a problem when a more detailed version of the format was used (the one that uses module versions or/and GUIDs). During module import, there is a check for cyclic references through 'RequiredModules' field. The bug was in this check for cyclic references, related to comparison rules for ModuleSpecification objects - as a result, the code was incorrectly reporting 'cyclic reference' error in cases when there was none. Also, added tests for different ModuleSpecification formats and a test for error when there is actually a cyclic reference.
|
Resolved via #3594 |
|
Is there any chance that this fix will be patched to Windows PowerShell (5.x)? |
|
@Jaykul I doubt it; but @SteveL-MSFT or @joeyaiello might have more info on this. |
|
@Jaykul at this time, there is no plan to port this to Windows PowerShell v5.1 |
|
I just want to come back here and point at AzureRM and scream. Did you realize that AzureRM (the "meta module" we all use to install all the Azure modules) doesn't have any Because, you know, if they used RequiredModules they would run into this bug. And they are NEVER going to be able to stop doing that.Not only do I not have any metadata about the dependencies of AzureRM (which is, basically, the entire reason for the existence of this module), but the Azure team is actually having to bypass the PowerShellGet module to publish to the gallery every time: they're adding the dependency information to the NuGet package even though it's not in the module. As a PowerShell scripter, there's no way for me to figure out that AzureRm.profile 3.4 is what shipped as part of AzureRm 4.4, and that AzureRm.profile 4.0 wasn't included until AzureRm version 5.0.0 -- except to query the gallery metadata As a PowerShell module author, I'm going to have to duplicate their hack to build metamodule nuspec files that don't reflect my module manifest... |
|
Is there any workaround for PowerShell 5.1 |
|
Can this be ported back 5.1 - we're going to be stuck with 5.1 for years and it's just poor experience. |
|
Stuck with the same issue in ADMF @sanderweltje : The only thing you can do right now is not declare the dependency and handle it internally (e.g. with warning during import or maybe even automatically installing it if missing - the latter being risky if you want to give your code to others, who may try it out in an offline scenario. |
|
Yeah. This bug forces anyone with a slightly complex chain of modules to do what the Azure team does. Compare the Az.psd1 source to Az.psd1 as published.
|
|
Oh, this is anguishing 😩 |
If a module (A) specifies the version of it's dependencies (the way it should), like:
Another module which takes the same dependency, and also depends on A will cause incorrect cyclic dependency errors.
Background
We recently split up a module into a few smaller modules, and created a meta-module to load them, such that a module "QMHelper" became: QM.Assembly, QM.Database, QM.Configuration, QM.Security, and ... QMHelper
Each of these modules depends on a few others, in a strictly linear fashion. E.g.:
QM.Assembly has no dependencies, but everything depends on it.
QM.Database depends only on QM.Assembly
QM.Configuration depends on QM.Database (and QM.Assembly)
...
QMHelper, of course, depends on every module, since it exists purely as an easy way to install them and import everything to maintain backwards compatibility.
Each of these dependencies is documented in the module's manifest with the minimum version and GUID. E.g.
@{ModuleName='QM.Database'; ModuleVersion='1.0'; GUID='0b8a2968-ea14-4e63-9961-d1dbee54faa5'}We believed that this was the right way to design large modules so that they can be installed easily, but only the parts that you need must be imported.
Bug Report:
A user script which had a
#requires -modules QMHelperin it failed to run. The error says that QMHelper was not loaded, but they can't figure out why. If theyImport-Module QMHelperfirst, it imports fine, and the script will run with no problems.It turns out that a
#requiresstatement counts as a level of dependency (just like RequiresModule), and when there are module versions involved, PowerShell gives up after just a few levels. Specifically, 5?In our case, we were just under the limit, and everything worked fine as long as you explicitly called Import-Module -- but if you used a
#requires -modulesstatement, or added our top-level module to yourRequiredModules, it would refuse to import, and give a confusing and incorrect error message.Steps to reproduce
I wrote a script to generate samples in a lot of different ways, but the simplest repro case is this:
Expected behavior
Import-Module should work, since the dependencies are simply linear.
Actual behavior
You'll get an error like this:
There is, of course, no cyclic dependency, and just changing the RequiresModules hashtable to a simple module name will clear up the error.
Without specifying the ModuleVersion in the manifest, you can go hundreds of layers deep.
Environment data
The text was updated successfully, but these errors were encountered: