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

declare None as default #127

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

declare None as default #127

wants to merge 2 commits into from

Conversation

dataders
Copy link

resolves #

Description

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md with information about my change

@tallamohan
Copy link
Contributor

@dataders , we already tried this solution, but failed with the below error:

non-default argument follows default argument

@septimit
Copy link
Contributor

septimit commented Nov 24, 2023

Hi all,
If I may jump into this conversation, the following diff works for me. As you can see one can enforce specific fields to be mandatory: in the diff below I've made server, username and password mandatory and removed database and schema field since they are inherited fields.

diff --git a/dbt/adapters/teradata/connections.py b/dbt/adapters/teradata/connections.py
index 8d71e00..9a984aa 100644
--- a/dbt/adapters/teradata/connections.py
+++ b/dbt/adapters/teradata/connections.py
@@ -15,11 +15,9 @@ from typing import Optional, Tuple, Any, Dict
 
 @dataclass
 class TeradataCredentials(Credentials):        
-    server: Optional[str] = None
-    database: Optional[str] = None
-    schema: Optional[str] = None
-    username: Optional[str] = None
-    password: Optional[str] = None
+    server: str
+    username: str
+    password: str
     port: Optional[str] = None
     tmode: Optional[str] = "ANSI"
     logmech: Optional[str] = None
@@ -74,10 +72,9 @@ class TeradataCredentials(Credentials):
             raise dbt.exceptions.DbtRuntimeError("Must specify `schema` in profile")
         
         # teradata classifies database and schema as the same thing
-        if (
-            self.database is not None and
-            self.database != self.schema
-        ):
+        if not self.database:
+            self.database = self.schema
+        elif self.database != self.schema:
             raise dbt.exceptions.DbtRuntimeError(
                 f"    schema: {self.schema} \n"
                 f"    database: {self.database} \n"
@@ -145,13 +142,11 @@ class TeradataCredentials(Credentials):
         )
     
     @classmethod
-    def __pre_deserialize__(cls, data: Dict[Any, Any]) -> Dict[Any, Any]:
-        # If database is not defined as adapter credentials
-        data = super().__pre_deserialize__(data)
-        if "database" not in data:
-            data["database"] = None
-        return data
-    
+    def translate_aliases(cls, kwargs: Dict[str, Any], recurse: bool = False) -> Dict[str, Any]:
+        if "database" not in kwargs:
+            kwargs["database"] = ''
+        return super().translate_aliases(kwargs, recurse)
+
 class TeradataConnectionManager(SQLConnectionManager):
     TYPE = "teradata"
     TMODE = "ANSI"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants