internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mabel-dev/opteryx

Issue:
🪲 VIEWs load error should be in debug mode only
### Thank you for taking the time to report a problem with Opteryx.
_To help us to respond to your request we ask that you try to provide the below detail about the bug._

**Describe the bug** _A clear and specific description of what the bug is. What the error, incorrect or unexpected behaviour was._


**Expected behaviour** _A clear and concise description of what you expected to happen._


**Sample Code/Statement** _If you can, please submit the SQL statement or Python code snippet, or a representative example using the sample datasets._

~~~sql

~~~

**Additional context** _Add any other context about the problem here, for example what you have done to try to diagnose or workaround the problem._



Discussion:

Resolving patch:
diff --git a/opteryx/planner/views/__init__.py b/opteryx/planner/views/__init__.py
--- a/opteryx/planner/views/__init__.py
+++ b/opteryx/planner/views/__init__.py
@@ -20,7 +20,7 @@ def _load_views():
         with open("views.json", "rb") as defs:
             return orjson.loads(defs.read())
     except Exception as err:
-        print(f"[OPTERYX] Unable to open views definition file. {err}")
+        # DEBUG:: log (f"[OPTERYX] Unable to open views definition file. {err}")
         return {}
 
 


Test patch:
Repository: mabel-dev/opteryx

Issue:
🪲 VIEWs load error should be in debug mode only
### Thank you for taking the time to report a problem with Opteryx.
_To help us to respond to your request we ask that you try to provide the below detail about the bug._

**Describe the bug** _A clear and specific description of what the bug is. What the error, incorrect or unexpected behaviour was._


**Expected behaviour** _A clear and concise description of what you expected to happen._


**Sample Code/Statement** _If you can, please submit the SQL statement or Python code snippet, or a representative example using the sample datasets._

~~~sql

~~~

**Additional context** _Add any other context about the problem here, for example what you have done to try to diagnose or workaround the problem._



Discussion:

Resolving patch:
diff --git a/opteryx/__version__.py b/opteryx/__version__.py
--- a/opteryx/__version__.py
+++ b/opteryx/__version__.py
@@ -1,4 +1,4 @@
-__build__ = 523
+__build__ = 526
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
diff --git a/opteryx/planner/views/__init__.py b/opteryx/planner/views/__init__.py
--- a/opteryx/planner/views/__init__.py
+++ b/opteryx/planner/views/__init__.py
@@ -20,7 +20,7 @@ def _load_views():
         with open("views.json", "rb") as defs:
             return orjson.loads(defs.read())
     except Exception as err:
-        print(f"[OPTERYX] Unable to open views definition file. {err}")
+        # DEBUG:: log (f"[OPTERYX] Unable to open views definition file. {err}")
         return {}
 
 


Test patch:
Repository: mabel-dev/opteryx

Issue:
🧹 [ClickBench] implement REGEXP_REPLACE
Query 29
~~~sql
SELECT REGEXP_REPLACE(Referer, '^https?://(?:www\.)?([^/]+)/.*$', '\1') AS k, 
    AVG(length(Referer)) AS l, 
    COUNT(*) AS c, 
    MIN(Referer) 
  FROM hits 
 WHERE Referer <> '' 
 GROUP BY k 
HAVING COUNT(*) > 100000 
 ORDER BY l DESC 
 LIMIT 25;
~~~


Discussion:

Resolving patch:
diff --git a/opteryx/__version__.py b/opteryx/__version__.py
--- a/opteryx/__version__.py
+++ b/opteryx/__version__.py
@@ -1,4 +1,4 @@
-__build__ = 540
+__build__ = 541
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -27,9 +27,9 @@ class VersionStatus(Enum):
 
 
 _major = 0
-_minor = 16
-_revision = 0
-_status = VersionStatus.ALPHA
+_minor = 15
+_revision = 1
+_status = VersionStatus.RELEASE
 
 __author__ = "@joocer"
 __version__ = f"{_major}.{_minor}.{_revision}" + (
diff --git a/opteryx/functions/__init__.py b/opteryx/functions/__init__.py
--- a/opteryx/functions/__init__.py
+++ b/opteryx/functions/__init__.py
@@ -320,6 +320,7 @@ def select_values(boolean_arrays, value_arrays):
     "LEVENSHTEIN": string_functions.levenshtein,
     "SPLIT": string_functions.split,
     "MATCH_AGAINST": string_functions.match_against,
+    "REGEXP_REPLACE": string_functions.regex_replace,
 
     # HASHING & ENCODING
     "HASH": _iterate_single_parameter(lambda x: hex(CityHash64(str(x)))[2:]),
diff --git a/opteryx/functions/string_functions.py b/opteryx/functions/string_functions.py
--- a/opteryx/functions/string_functions.py
+++ b/opteryx/functions/string_functions.py
@@ -346,3 +346,10 @@ def match_against(arr, val):
         and set(tokenized_literal).issubset(tok)
         for tok in tokenized_strings
     ]
+
+def regex_replace(array, _pattern, _replacement):
+
+    pattern = _pattern[0]
+    replacement = _replacement[0]
+
+    return compute.replace_substring_regex(array, pattern, replacement)


Test patch:
diff --git a/tests/sql_battery/test_shapes_and_errors_battery.py b/tests/sql_battery/test_shapes_and_errors_battery.py
--- a/tests/sql_battery/test_shapes_and_errors_battery.py
+++ b/tests/sql_battery/test_shapes_and_errors_battery.py
@@ -1347,6 +1347,7 @@
         ("SELECT $missions.* FROM $missions INNER JOIN $user ON Mission = value WHERE attribute = 'membership'", 1, 8, None),
         ("SELECT * FROM $planets WHERE name = any(@@user_memberships)", 0, 20, None),
         ("SELECT name FROM sqlite.planets WHERE name = ANY(('Earth', 'Mars'))", 2, 1, None),
+        ("SELECT name FROM $planets WHERE REGEXP_REPLACE(name, '^E', 'G') == 'Garth'", 1, 1, None),
 
         # TEST FUNCTIONS
         ("EXECUTE PLANETS_BY_ID (id=1)", 1, 20, None),  # simple case
Repository: koxudaxi/datamodel-code-generator

Issue:
Use `Optional` for nullable fields?
If a field is `nullable` (https://swagger.io/docs/specification/data-models/data-types/#null) use the `Optional` type hint (https://pydantic-docs.helpmanual.io/#pep-484-types)


Discussion:

Resolving patch:
diff --git a/datamodel_code_generator/__main__.py b/datamodel_code_generator/__main__.py
--- a/datamodel_code_generator/__main__.py
+++ b/datamodel_code_generator/__main__.py
@@ -7,6 +7,7 @@
 import os
 import sys
 from argparse import ArgumentParser, FileType
+from datetime import datetime, timezone
 from enum import IntEnum
 from typing import Optional, Sequence
 
@@ -41,8 +42,20 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
 
     input_filename = os.path.abspath(os.path.expanduser(args.input))
     parser = Parser(BaseModel, DataModelField, filename=input_filename)
+    timestamp = datetime.now(timezone.utc).replace(microsecond=0).isoformat()
+    header = f"""\
+# generated by datamodel-codegen:
+#   filename:  {os.path.split(input_filename)[1]}
+#   timestamp: {timestamp}
+
+from typing import List, Optional
+
+from pydantic import BaseModel
+
+
+"""
     with args.output as file:
-        parser.parse(file)
+        print(header, file=file)
         print(parser.parse(), file=file)
 
     return Exit.OK
diff --git a/datamodel_code_generator/parser/openapi.py b/datamodel_code_generator/parser/openapi.py
--- a/datamodel_code_generator/parser/openapi.py
+++ b/datamodel_code_generator/parser/openapi.py
@@ -1,6 +1,6 @@
-from dataclasses import Field, dataclass
 from typing import Dict, List, Optional, Set, Type, Union
 
+from dataclasses import Field, dataclass
 from prance import BaseParser, ResolvingParser
 
 from ..model import CustomRootType, DataModel, DataModelField


Test patch:
Repository: koxudaxi/datamodel-code-generator

Issue:
IPv4Address doesn't import from pydantic.validators
**Describe the bug**

When using `format: ipv4`, the following import is added to the output:

```py
from pydantic import IPv4Address
```

This isn't a valid import.

**To Reproduce**

Example schema:
```yaml
openapi: 3.0.0

info:
  version: 0.0.1
  title: Foo API

paths:
  /foo:
    get:
      responses:
        "200":
          description: Success

components:
  schemas:
    Foo:
      type: object
      properties:
        ip:
          type: string
          format: ipv4
```

Used commandline:
```
$ datamodel-codegen --input openapi.yaml
```

**Expected behavior**

When using `format: ipv4`, the following import is added to the output:

```py
from pydantic.validators import IPv4Address
```

**Version:**
 - OS: MacOS
 - Python version: `3.9.2`
 - datamodel-code-generator version: `0.8.2`

**Additional context**
None



Discussion:

Resolving patch:
diff --git a/datamodel_code_generator/model/pydantic/imports.py b/datamodel_code_generator/model/pydantic/imports.py
--- a/datamodel_code_generator/model/pydantic/imports.py
+++ b/datamodel_code_generator/model/pydantic/imports.py
@@ -17,8 +17,8 @@
 IMPORT_UUID4 = Import.from_full_path('pydantic.UUID4')
 IMPORT_UUID5 = Import.from_full_path('pydantic.UUID5')
 IMPORT_ANYURL = Import.from_full_path('pydantic.AnyUrl')
-IMPORT_IPV4ADDRESS = Import.from_full_path('pydantic.IPv4Address')
-IMPORT_IPV6ADDRESS = Import.from_full_path('pydantic.IPv6Address')
+IMPORT_IPV4ADDRESS = Import.from_full_path('ipaddress.IPv4Address')
+IMPORT_IPV6ADDRESS = Import.from_full_path('ipaddress.IPv6Address')
 IMPORT_EXTRA = Import.from_full_path('pydantic.Extra')
 IMPORT_FIELD = Import.from_full_path('pydantic.Field')
 IMPORT_STRICT_INT = Import.from_full_path('pydantic.StrictInt')


Test patch:
diff --git a/tests/parser/test_jsonschema.py b/tests/parser/test_jsonschema.py
--- a/tests/parser/test_jsonschema.py
+++ b/tests/parser/test_jsonschema.py
@@ -354,8 +354,8 @@ def test_parse_nested_array():
         ('string', 'uuid3', 'UUID3', 'pydantic', 'UUID3'),
         ('string', 'uuid4', 'UUID4', 'pydantic', 'UUID4'),
         ('string', 'uuid5', 'UUID5', 'pydantic', 'UUID5'),
-        ('string', 'ipv4', 'IPv4Address', 'pydantic', 'IPv4Address'),
-        ('string', 'ipv6', 'IPv6Address', 'pydantic', 'IPv6Address'),
+        ('string', 'ipv4', 'IPv4Address', 'ipaddress', 'IPv4Address'),
+        ('string', 'ipv6', 'IPv6Address', 'ipaddress', 'IPv6Address'),
         ('string', 'unknown-type', 'str', None, None),
     ],
 )
Repository: koxudaxi/datamodel-code-generator

Issue:
Custom template directory is ignored for Enums
First of all, thanks for this great library, what a time saver ! :+1: 

**Describe the bug**
If you pass a custom template directory through the cli, this directory is ignored while generating enums.

**To Reproduce**
Simply lauch the cli with `--custom-template-dir`

Example schema: Any schema will do

Used commandline:
```
$ datamodel-codegen --custom-template-dir /path/to/alternative/templates
```
where `/path/to/alternative/templates` has an `Enum.jinja2` file in it.

**Expected behavior**
The custom `Enum.jinja2` is the one getting rendered when an Enum model is needed

**Version:**
 - OS: Gentoo
 - Python version: 3.8.9
 - datamodel-code-generator version: 0.11.4

**Additional context**
I originally needed to update the template for enums as I need enums to inherit from `str` also, so serializing them give the actual value, not the representation of an enum value.


Discussion:

Resolving patch:
diff --git a/datamodel_code_generator/parser/jsonschema.py b/datamodel_code_generator/parser/jsonschema.py
--- a/datamodel_code_generator/parser/jsonschema.py
+++ b/datamodel_code_generator/parser/jsonschema.py
@@ -877,6 +877,7 @@ def create_enum(reference_: Reference) -> DataType:
                 fields=enum_fields,
                 path=self.current_source_path,
                 description=obj.description if self.use_schema_description else None,
+                custom_template_dir=self.custom_template_dir,
             )
             self.results.append(enum)
             return self.data_type(reference=reference_)


Test patch:
Repository: koxudaxi/datamodel-code-generator

Issue:
--enum-field-as-literal=one converts integer to string
**Describe the bug**

When using the `--enum-field-as-literal=one` arg, the generated literal is always a string. Even if you explicitly set `type: integer`.

**To Reproduce**

Example schema:
```yaml
Foo:
  type: object
  properties:
    bar:
      type: integer
      enum: [1]
```

Creates:

```py
class Foo(BaseModel):
    bar: Optional[Literal['1']] = None
```

Used commandline:
```
$ datamodel-codegen --input openapi.yaml --output models.py --enum-field-as-literal=one
```

**Expected behavior**

If an enum type is `integer` then the resulting literal is also an integer.

**Version:**
 - OS: macOS `11.4`
 - Python version: `3.9.2`
 - datamodel-code-generator version: `0.11.6`

**Additional context**

This appears to be a problem with this type:

https://github.com/koxudaxi/datamodel-code-generator/blob/master/datamodel_code_generator/types.py#L74

Changing that type to `List[int]` results in an int literal. Not that we should change the type to `List[int]` specifically, but rather that the type likely needs to be more flexible.



Discussion:
Thank you for creating this issue.

> If an enum type is integer then the resulting literal is also an integer.

I didn't expect integer or other literal types. :cry: 

> Changing that type to List[int] results in an int literal. Not that we should change the type to List[int] specifically, but rather that the type likely needs to be more flexible.

Yes, it should accept other types too.

Resolving patch:
diff --git a/datamodel_code_generator/types.py b/datamodel_code_generator/types.py
--- a/datamodel_code_generator/types.py
+++ b/datamodel_code_generator/types.py
@@ -16,6 +16,7 @@
     Tuple,
     Type,
     TypeVar,
+    Union,
 )
 
 from pydantic import create_model
@@ -71,7 +72,7 @@ class DataType(_BaseModel):
     is_dict: bool = False
     is_list: bool = False
     is_custom_type: bool = False
-    literals: List[str] = []
+    literals: List[Union[int, str]] = []
     use_standard_collections: bool = False
     use_generic_container: bool = False
     alias: Optional[str] = None


Test patch:
Repository: koxudaxi/datamodel-code-generator

Issue:
Not `None` default values for arg_parse override settings in `pyproject.toml`
**Describe the bug**
`collapse-root-models = true` is ignored, when set via `pyproject.toml` 

**To Reproduce**

Example schema:
[`error.schema`](https://raw.githubusercontent.com/folio-org/raml/69f6074f5f48fd58e379e9ae76c892aa68c115ea/schemas/error.schema) and the referenced [`parameters.schema`](https://raw.githubusercontent.com/folio-org/raml/69f6074f5f48fd58e379e9ae76c892aa68c115ea/schemas/parameters.schema)

Used commandline:
```
$ datamodel-codegen --url https://raw.githubusercontent.com/folio-org/raml/4aaeffa22d5461b41ac761870dcfce58bf8db387/schemas/error.schema  
```

**Expected behavior**
After adding the `collapse-root-models` entry to the `pyproject.toml` this should result in the same output as 
```
datamodel-codegen --collapse-root-models --url https://raw.githubusercontent.com/folio-org/raml/4aaeffa22d5461b41ac761870dcfce58bf8db387/schemas/error.schema  
```

**Version:**
 - OS: Linux
 - Python version: Python 3.10.7
 - datamodel-code-generator version: 0.16.0

**Additional context**



Discussion:

Resolving patch:
diff --git a/datamodel_code_generator/__main__.py b/datamodel_code_generator/__main__.py
--- a/datamodel_code_generator/__main__.py
+++ b/datamodel_code_generator/__main__.py
@@ -269,7 +269,7 @@ def sig_int_handler(_: int, __: Any) -> None:  # pragma: no cover
 arg_parser.add_argument(
     "--collapse-root-models",
     action='store_true',
-    default=False,
+    default=None,
     help="Models generated with a root-type field will be merged"
     "into the models using that root-type model",
 )


Test patch:
Repository: koxudaxi/datamodel-code-generator

Issue:
` --use-default-kwarg` breaks codegen with default_factory `Field(default=default_factory=...`
**Describe the bug**
When using ` --use-default-kwarg` on models with a default_factory codegen breaks:  `Field(default=default_factory=...`


```
File "src\black\parsing.py", line 127, in lib2to3_parse
black.parsing.InvalidInput: Cannot parse: 17:54:     foo: Optional[Foo] = Field(default=default_factory=lambda :Foo.parse_obj({'foo': 'foo'}), title='Foo')
```
**To Reproduce**

Example schema:
```json

{
    "title": "Requests",
    "definitions": {
        "Foo": {
            "title": "Foo",
            "type": "object",
            "properties": {
                "foo": {
                    "title": "Foo",
                    "default": "foo",
                    "type": "string"
                }
            }
        },
        "Bar": {
            "title": "Bar",
            "type": "object",
            "properties": {
                "foo": {
                    "title": "Foo",
                    "default": {
                        "foo": "foo"
                    },
                    "allOf": [
                        {
                            "$ref": "#/definitions/Foo"
                        }
                    ]
                }
            }
        }
    }
}

```

Used commandline:
```
$ datamodel-codegen --input schema.json --output model.py --use-default-kwarg
```

**Expected behavior**
Such a model should be produced
``` python
class Foo(BaseModel):
    foo: Optional[str] = Field(default='foo', title='Foo')


class Bar(BaseModel):
    foo: Optional[Foo] = Field(default_factory=lambda: Foo.parse_obj({'foo': 'foo'}), title='Foo')

```

**Version:**

✅ works in 0.16.1
❌ breaks in 0.17.0 (probably introduced by https://github.com/koxudaxi/datamodel-code-generator/pull/1047 )
- python 3.11.1
- windows 11


Discussion:

Resolving patch:
diff --git a/datamodel_code_generator/model/pydantic/base_model.py b/datamodel_code_generator/model/pydantic/base_model.py
--- a/datamodel_code_generator/model/pydantic/base_model.py
+++ b/datamodel_code_generator/model/pydantic/base_model.py
@@ -69,7 +69,11 @@ def validator(self) -> Optional[str]:
     def field(self) -> Optional[str]:
         """for backwards compatibility"""
         result = str(self)
-        if self.use_default_kwarg and not result.startswith('Field(...'):
+        if (
+            self.use_default_kwarg
+            and not result.startswith('Field(...')
+            and not result.startswith('Field(default_factory=')
+        ):
             # Use `default=` for fields that have a default value so that type
             # checkers using @dataclass_transform can infer the field as
             # optional in __init__.


Test patch:
Repository: koxudaxi/datamodel-code-generator

Issue:
`remove_special_field_name_prefix` flag with fields beginning with numbers
**Describe the bug**
If you have fields which are beginning with numbers you can't use the `remove_special_field_name_prefix` flag. If you do so it results in an endless loop somewhere. This is because the `FieldNameResolver` prepends the name with an underscore if it begins with a number. Which would then be removed again if `remove_special_field_name_prefix` is set resulting in an invalid identifier.

**To Reproduce**

Example schema:
```json
{
	"description": "Blabla",
	"enum": [
		"SOME_NORMAL",
		"21_HALF_NORMAL",
                "_SOME_FANCY",
	],
	"title": "ClassA",
	"type": "string"
}
```

Used commandline:
```
$ datamodel-codegen --input some/file.json --output some/output.py --remove_special_field_name_prefix
```

**Expected behavior**
Prepend the field `21_HALF_NORMAL` with the value of `special_field_name_prefix` while being able to remove the underscore from `_SOME_FANCY`.
More specifically, something like that:
```python
class ClassA(Enum):
    SOME_NORMAL = "SOME_NORMAL"
    FIELD_21_HALF_NORMAL = "21_HALF_NORMAL"
    SOME_FANCY = "_SOME_FANCY"
```

**Version:**
 - OS: Windows 11
 - Python version: 3.11
 - datamodel-code-generator version: 0.22.1


Discussion:
I would also suggest to change the description of the option to something like
```
  --remove-special-field-name-prefix
                        Remove field name prefix if it has a special 
                        meaning e.g. underscores
```

Resolving patch:
diff --git a/datamodel_code_generator/arguments.py b/datamodel_code_generator/arguments.py
--- a/datamodel_code_generator/arguments.py
+++ b/datamodel_code_generator/arguments.py
@@ -297,7 +297,7 @@ def start_section(self, heading: Optional[str]) -> None:
 )
 field_options.add_argument(
     '--remove-special-field-name-prefix',
-    help="Remove field name prefix when first character can't be used as Python field name",
+    help='Remove field name prefix if it has a special meaning e.g. underscores',
     action='store_true',
     default=None,
 )
diff --git a/datamodel_code_generator/reference.py b/datamodel_code_generator/reference.py
--- a/datamodel_code_generator/reference.py
+++ b/datamodel_code_generator/reference.py
@@ -229,7 +229,7 @@ def get_valid_name(
 
         name = re.sub(r'[¹²³⁴⁵⁶⁷⁸⁹]|\W', '_', name)
         if name[0].isnumeric():
-            name = f'_{name}'
+            name = f'{self.special_field_name_prefix}_{name}'
 
         # We should avoid having a field begin with an underscore, as it
         # causes pydantic to consider it as private


Test patch:
Repository: koxudaxi/datamodel-code-generator

Issue:
Impossible to get the json schema of a json schema object
**Describe the bug**

```python
from datamodel_code_generator.parser.jsonschema import JsonSchemaObject

if __name__ == "__main__":
    print(JsonSchemaObject.model_json_schema())
```

Raises

```
pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'no-info', 'function': <bound method UnionIntFloat.validate of <class 'datamodel_code_generator.types.UnionIntFloat'>>})
```

**To Reproduce**

See code above

**Expected behavior**

The json schema of a json schema object.

**Version:**
 - OS: Linux 6.2.0
 - Python version: 3.11.4
 - datamodel-code-generator version: 0.22.1



Discussion:
Seems like the problem comes from this line:
https://github.com/koxudaxi/datamodel-code-generator/blob/979444cdd4cbfbfab489f6f4c9bb09f8eaf8553b/datamodel_code_generator/types.py#L132

Replacing that line by the following content seems to fix the problem.
```python
json_schema=from_int_schema,
```

Resolving patch:
diff --git a/datamodel_code_generator/types.py b/datamodel_code_generator/types.py
--- a/datamodel_code_generator/types.py
+++ b/datamodel_code_generator/types.py
@@ -129,7 +129,7 @@ def __get_pydantic_core_schema__(
         )
 
         return core_schema.json_or_python_schema(
-            json_schema=core_schema.no_info_plain_validator_function(cls.validate),
+            json_schema=from_int_schema,
             python_schema=core_schema.union_schema(
                 [
                     # check if it's an instance first before doing any further work


Test patch: