@@ -103,14 +103,7 @@ def prepare(self):
103103
104104 def _parse_json (self ):
105105 if not self .request .body :
106- raise HTTPError (
107- 400 ,
108- reason = (
109- "Empty body is not a valid JSON. "
110- "Remove the content-type header, or "
111- "provide an empty object in the body."
112- ),
113- )
106+ return {}
114107 try :
115108 return orjson .loads (self .request .body )
116109 except orjson .JSONDecodeError :
@@ -126,32 +119,37 @@ def _parse_args(self, reqargs):
126119 if not self .name : # feature disabled
127120 return {} # default value
128121
129- # Handle handlers that don't define a unique name attribute
122+ # Check if handler defines kwargs but not a unique name - this is an error
130123 if self .name == "__base__" and self .__class__ != BaseAPIHandler :
131- logger . warning (
132- f"Handler { self . __class__ . __name__ } inherits from BaseAPIHandler but doesn't define "
133- f"a unique 'name' attribute. This may cause parameter validation conflicts. "
134- f"Please add: name = 'your_handler_name' to the class definition for consistent behavior."
124+ # Check if this handler defines its own kwargs (not inherited from BaseAPIHandler)
125+ handler_has_kwargs = (
126+ hasattr ( self . __class__ , 'kwargs' ) and
127+ self . __class__ . kwargs is not BaseAPIHandler . kwargs
135128 )
136- # For handlers with missing names, return empty args to avoid conflicts
137- # This mimics the behavior when name is None
138- return {}
139- else :
140- actual_name = self .name
129+
130+ if handler_has_kwargs :
131+ # Handler defines kwargs but uses default name - this will cause conflicts
132+ raise HTTPError (
133+ 500 ,
134+ reason = (
135+ f"Handler { self .__class__ .__name__ } defines 'kwargs' but doesn't define "
136+ f"a unique 'name' attribute. This causes parameter validation conflicts. "
137+ f"Please add: name = 'your_handler_name' to the class definition."
138+ )
139+ )
140+ else :
141+ # Handler doesn't define kwargs and doesn't define name - this is ok
142+ # Return empty args to disable parameter validation
143+ return {}
141144
142145 optionsets = self .biothings .optionsets
143- optionset = optionsets .get (actual_name )
146+ optionset = optionsets .get (self . name )
144147
145148 # Initialize args variable for the finally block
146149 args = None
147150
148151 try : # uses biothings.web.options to standardize args
149- if optionset :
150- args = optionset .parse (self .request .method , reqargs )
151- else :
152- # If no optionset found, return empty args (same as when name is None)
153- args = {}
154- return args
152+ args = optionset .parse (self .request .method , reqargs )
155153
156154 except OptionError as err :
157155 args = err # for logging in "finally" clause
0 commit comments