Skip to content

Commit

Permalink
fix(psl): don't trust datasource array to contain at least 1 datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed Oct 31, 2024
1 parent 8ce72a2 commit f74a000
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 7 additions & 2 deletions psl/psl-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ fn validate_configuration(
// We need to know the active provider to determine which features are active.
// This was originally introduced because the `fullTextSearch` preview feature will hit GA stage
// one connector at a time (Prisma 6 GAs it for MySQL, other connectors may follow in future releases).
let active_provider = datasources[0].active_provider;
let generators = generator_loader::load_generators_from_ast(schema_ast, diagnostics, active_provider);
let feature_map_with_provider = datasources

Check failure on line 179 in psl/psl-core/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy linting

accessing first element with `datasources.get(0)`
.get(0)
.map(|ds| ds.active_provider)
.map(FeatureMapWithProvider::new)
.unwrap_or_else(|| ALL_PREVIEW_FEATURES);

let generators = generator_loader::load_generators_from_ast(schema_ast, diagnostics, &feature_map_with_provider);

Configuration::new(generators, datasources, diagnostics.warnings().to_owned())
}
8 changes: 3 additions & 5 deletions psl/psl-core/src/validate/generator_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const FIRST_CLASS_PROPERTIES: &[&str] = &[PROVIDER_KEY, OUTPUT_KEY, BINARY_TARGE
pub(crate) fn load_generators_from_ast(
ast_schema: &ast::SchemaAst,
diagnostics: &mut Diagnostics,
connector_provider: &str,
feature_map_with_provider: &FeatureMapWithProvider<'_>,
) -> Vec<Generator> {
let mut generators: Vec<Generator> = Vec::new();

for gen in ast_schema.generators() {
if let Some(generator) = lift_generator(gen, diagnostics, connector_provider) {
if let Some(generator) = lift_generator(gen, diagnostics, feature_map_with_provider) {
generators.push(generator);
}
}
Expand All @@ -41,7 +41,7 @@ pub(crate) fn load_generators_from_ast(
fn lift_generator<'a>(

Check failure on line 41 in psl/psl-core/src/validate/generator_loader.rs

View workflow job for this annotation

GitHub Actions / clippy linting

this lifetime isn't used in the function definition
ast_generator: &ast::GeneratorConfig,
diagnostics: &mut Diagnostics,
connector_provider: &'a str,
feature_map_with_provider: &FeatureMapWithProvider<'_>,
) -> Option<Generator> {
let generator_name = ast_generator.name.name.as_str();
let args: HashMap<_, &Expression> = ast_generator
Expand Down Expand Up @@ -97,8 +97,6 @@ fn lift_generator<'a>(
.and_then(|arg| coerce_array(arg, &StringFromEnvVar::coerce, diagnostics))
.unwrap_or_default();

let feature_map_with_provider = FeatureMapWithProvider::<'a>::new(connector_provider);

// for compatibility reasons we still accept the old experimental key
let preview_features = args
.get(PREVIEW_FEATURES_KEY)
Expand Down

0 comments on commit f74a000

Please sign in to comment.