dbt-teradata icon indicating copy to clipboard operation
dbt-teradata copied to clipboard

declare None as default

Open dataders opened this issue 2 years ago • 2 comments

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

dataders avatar Nov 20 '23 19:11 dataders

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

non-default argument follows default argument

tallamohan avatar Nov 21 '23 01:11 tallamohan

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"

septimit avatar Nov 24 '23 12:11 septimit

The Issue was resolved Closing this PR

VarunSharma15 avatar Dec 04 '24 05:12 VarunSharma15