这是indexloc提供的服务,不要输入任何密码
Skip to content

track table check conflicting node doesn't take source customization into account #9268

@dsandip

Description

@dsandip

Issue

When we are tracking a table, Hasura checks for conflicting nodes by running the following introspection query:

{
  __schema {
    queryType {
      fields {
        name
      }
    }
  }
}

And checks if the "table name" which is going to be tracked already exists or not. This is alright unless the source is having any source customization associated with it. There are two possible ways to trick this behaviour:

  1. Track a table, say prefix_foo and then add another source with root_fields.prefix set to prefix_. Now try adding a table foo to the new source and track it. Ideally this should have been caught by the checkConflictingNode, but it doesn't. This gets caught in the later step.
  2. Track a table say, foo and add another source with root_fields.prefix set to say prefix_, now try adding a table called foo in the new source. This should be allowed as the names don't conflict, but the checkConflictingNode will raise an error.

Possible solution

Create a function which can generate the root field names based on the source customization and the new table name which needs to be tracked (following the naming convention set). Please note that this should return the namespace if the source customization have any.

getRootFieldNames :: SourceCustomization -> Text -> [Text]
getRootFieldNames sCustomization tableName = undefined

Then run the checkConflictingNode with these names.

trackExistingTableOrViewP2 ::
  forall b m.
  (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
  SourceName ->
  TableName b ->
  Bool ->
  TableConfig b ->
  m EncJSON
trackExistingTableOrViewP2 source tableName isEnum config = do
  sc <- askSchemaCache
  sourceCustomization <- (fmap (\e -> AB.dispatchAnyBackend @Backend e _smCustomization) . OMap.lookup source . _metaSources) <$> getMetadata
  let
    fieldNames = getRootFieldNames sourceCustomization tableName
  {-
  The next line does more than what it says on the tin.  Removing the following ...
  -}
  
  forM_ fieldNames (checkConflictingNode sc) -- checkConflictingNode sc $ snakeCaseTableName @b tableName
  ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions