Skip to content

DacFx fails to generate dependency in subqueries within FROM VALUES clause #156

@zijchen

Description

@zijchen
  • SqlPackage or DacFx Version: 16.0.6296.0
  • .NET Framework (Windows-only) or .NET Core: Both
  • Environment (local platform and source/target platforms): repros in Azure and SQL 2022, presumably in earlier versions too

Steps to Reproduce:

Build a DACPAC from the below scripts, it will fail to publish with error Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 208, Level 16, State 1, Procedure View1, Line 4 Invalid object name 'View2'.

CREATE TABLE [dbo].[Table1] ( [A] INT NULL );

GO;

CREATE VIEW [dbo].[View1]
AS
SELECT MAX(B) AS B
FROM (VALUES ((SELECT MAX(A) AS B FROM View2)), (1)) AS T(B);

GO;

CREATE VIEW [dbo].[View2] AS SELECT [A] FROM [Table1];

GO;

The issue lies within the subquery in View1's FROM VALUES clause. The query references View2, but it seems like DacFx is ignoring that dependency and deploying the objects in alphabetical order.

Inspecting the model.xml you can see the relationship from View1 to View2 is missing:

<Element Type="SqlView" Name="[dbo].[View1]">
	<Property Name="QueryScript">
		<Value><![CDATA[
SELECT MAX(B) AS B
FROM (VALUES ((SELECT MAX(A) AS B FROM View2)), (1)) AS T(B)]]></Value>
	</Property>
	<Property Name="IsAnsiNullsOn" Value="True" />
	<Relationship Name="Columns">
		<Entry>
			<Element Type="SqlComputedColumn" Name="[dbo].[View1].[B]" />
		</Entry>
	</Relationship>
	<Relationship Name="Schema">
		<Entry>
			<References ExternalSource="BuiltIns" Name="[dbo]" />
		</Entry>
	</Relationship>
        ...
</Element>

Metadata

Metadata

Assignees

Labels

area: model resolverRelated to issues resolving dependencies when building schema modelbugSomething isn't workingfixed-pending-releaseFix in upcoming release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions