我在 Windows 上安装了 PostgreSQL 11 和 PGadmin 4。目前,我已连接到托管我所有数据的 AWS 服务器。
我想创建一个本地服务器 (localhost) 作为我可以进行实验的测试环境。不过,我似乎无法做到,堆栈上的其他类似问题也无济于事。这是我的过程:
在 pgAdmin 中,右键单击“服务器”并转到“创建”>“服务器”
在“创建 - 服务器”弹出框中,我输入名称:Localserver。对于“连接”,我输入 localhost。端口我保持默认'5432',db:postgres,用户名:postgres 密码:空
点击保存。
但是,我收到一个错误:
无法连接到服务器:
无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?
无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(127.0.0.1) 上运行并接受端口 5432 上的 TCP/IP 连接?
我该怎么办?如果这有所作为,我是管理员。
我正在使用 PyCharm 并正在编写 pytest 单元测试。我可以正常运行测试,但如果我尝试调试它,调试器就会崩溃。
Windows 致命异常:访问冲突
线程0x00003588(最近一次调用首先):文件“C:\ Users \ MyUserName \ AppData \ Local \ Programs \ Python \ Python310 \ lib \ threading.py”,等待文件“C:\ Users \ MyUserName \ AppData \”中的第324行Local\Programs\Python\Python310\lib\threading.py”,等待文件中的第 600 行“C:\Program Files\JetBrains\PyCharm 2021.1\plugins\python\helpers\pydev\pydevd.py”,_on_run 文件中的第 150 行“C:\Program Files\JetBrains\PyCharm 2021.1\plugins\python\helpers\pydev_pydevd_bundle\pydevd_comm.py”,运行文件“C:\Users\MyUserName\AppData\Local\Programs\Python\Python310\lib\”中的第 218 行threading.py”,_bootstrap_inner 中的第 1009 行 文件“C:\Users\MyUserName\AppData\Local\Programs\Python\Python310\lib\threading.py”,_bootstrap 中的第 966 行
线程 0x000023f0(最近一次调用首先):文件“C:\Program Files\JetBrains\PyCharm 2021.1\plugins\python\helpers\pydev_pydevd_bundle\pydevd_comm.py”,_on_run 文件“C:\Program Files\JetBrains\PyCharm 中的第 292 行” 2021.1\plugins\python\helpers\pydev_pydevd_bundle\pydevd_comm.py”,运行文件中的第 218 行“C:\Users\MyUserName\AppData\Local\Programs\Python\Python310\lib\threading.py”,_bootstrap_inner 文件中的第 1009 行“C:\ Users \ MyUserName \ AppData \ Local \ Programs \ Python \ Python310 \ …
在下面的 MWE 中,我有两个文件/模块:
main.py这是并且应该用 mypy 检查importedmodule.py不应进行类型检查,因为它是自动生成的。该文件是自动生成的,我不想添加type:ignore.$ mypy main.py --exclude '.*importedmodule.*'
Run Code Online (Sandbox Code Playgroud)
$ mypy --version
mypy 0.931
Run Code Online (Sandbox Code Playgroud)
"""
This should be type checked
"""
from importedmodule import say_hello
greeting = say_hello("Joe")
print(greeting)
Run Code Online (Sandbox Code Playgroud)
"""
This module should not be checked in mypy, because it is excluded
"""
def say_hello(name: str) -> str:
# This function is imported and called from my type checked code
return f"Hello {name}!"
def return_an_int() -> int: …Run Code Online (Sandbox Code Playgroud) 我正在解组到一个具有time.Time名为 Foo 的字段的结构:
type AStructWithTime struct {
Foo time.Time `json:"foo"`
}
Run Code Online (Sandbox Code Playgroud)
我的期望是,解组后我会得到这样的结果:
var expectedStruct = AStructWithTime{
Foo: time.Date(2022, 9, 26, 21, 0, 0, 0, time.UTC),
}
Run Code Online (Sandbox Code Playgroud)
当使用纯 json 字符串时,这工作得很好:
func Test_Unmarshalling_DateTime_From_String(t *testing.T) {
jsonStrings := []string{
"{\"foo\": \"2022-09-26T21:00:00Z\"}", // trailing Z = UTC offset
"{\"foo\": \"2022-09-26T21:00:00+00:00\"}", // explicit zero offset
"{\"foo\": \"2022-09-26T21:00:00\u002b00:00\"}", // \u002b is an escaped '+'
}
for _, jsonString := range jsonStrings {
var deserializedStruct AStructWithTime
err := json.Unmarshal([]byte(jsonString), &deserializedStruct)
if …Run Code Online (Sandbox Code Playgroud) I'm reading data from a SAP Core Data Service (CDS view, SAP R/3, ABAP 7.50) using a WHERE clause on its primary (and only) key column. There is a massive performance decrease when using FOR ALL ENTRIES (about a factor 5):
Reading data using a normal WHERE clause takes about 10 seconds in my case:
SELECT DISTINCT *
FROM ZMY_CDS_VIEW
WHERE prim_key_col eq 'mykey'
INTO TABLE @DATA(lt_table1).
Run Code Online (Sandbox Code Playgroud)
Reading data using FOR ALL ENTRIES with the same WHERE takes about 50 …
我想将JSON中使用的键转换为其他语言。
我知道从技术角度来看,在设计接口,API等时,这似乎是胡说八道。为什么不首先使用英语?好吧,我没有写这个要求;)
/// <summary>serialization language</summary>
public enum Language
{
/// <summary>English</summary>
EN,
/// <summary>German</summary>
DE
// some more ...
}
Run Code Online (Sandbox Code Playgroud)
实现此目的的最简单方法可能是一个属性:
/// <summary>An Attribute to add different "translations"</summary>
public class TranslatedFieldName : Attribute
{
public string Name { get; }
public Language Lang{ get; }
// actually there might be a dictionary with lang-name pairs later on; but let's keep it simple
public TranslatedFieldName(string translatedName, Language lang)
{
this.Lang = lang;
this.Name = translatedName;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,将此属性添加到要序列化的类中:
/// <summary>I want …Run Code Online (Sandbox Code Playgroud) 我想使用 Flask + SQLAlchemy 构建一个多租户应用程序。官方 SQLAlchemy 文档建议,要使用多租户,表应该分布在每个租户的 1 个方案上,并在引擎级别处理不同的租户。
维护多个方案对我来说似乎有点臃肿,我想知道如果设计正确,以下方法对所有租户使用相同的表是否可行,如果不是,为什么不:
tenant_id,指示哪个租户“拥有”该行。INSERT和UPDATE)自动将此列的值设置为当前租户。SELECT或DELETE)查询会自动WHERE tenant_id=:current tenant向 SQL添加子句/过滤器。tenant_id可以派生自 JSON Web 令牌。我几乎找不到关于这种方法的任何信息(除了这个名为MultiAlchemy 的软件包,它似乎与我的描述类似,但已存档且 7 年未更新)。我的直觉说,这是有原因的。
tl;dr:为什么不在 SQLAlchemy 中使用共享方案进行多租户?
在我的控制器中,有一种方法 take 接受一个路由和一个查询参数作为参数:
/// <summary>
/// My Method
/// </summary>
/// <param name="routeParameter">Nice description of route parameter.</param>
/// <param name="queryParameter">Nice description of query paramter.</param>
[HttpPost("somePath/{routeParameter}")]
public IActionResult MyMethod([FromRoute] string routeParameter, [FromQuery] DateTime queryParamter)
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
在通过 Swashbuckle XML 从此签名生成的 OpenApi.json / Swagger 中,routeParameter(路径)始终是必需的,但 queryParameter(查询)被标记为可选。
我如何也将查询参数标记为必需?
我正在对我的 Flask 应用程序进行单元测试。测试的代码如下:
@app.route("/my_endpoint/", methods=["GET"])
def say_hello():
"""
Greets the user.
"""
name = request.args.get("name")
return f"Hello {name}"
Run Code Online (Sandbox Code Playgroud)
测试看起来像这样:
class TestFlaskApp:
def test_my_endpoint(self):
"""
Tests that my endpoint returns the result as plain text.
:return:
"""
client = app.test_client()
response = client.get("/my_endpoint?name=Peter")
assert response.status_code == status.HTTP_200_OK
assert response.data.decode() == "Hello Peter"
Run Code Online (Sandbox Code Playgroud)
错误是:
预计:200 实际:308
因此,我得到的不是“确定”(200),而是“永久重定向”(308)
将 Pycharm 升级到 2023.3.3(内部版本 #PY-233.13763.11,构建于 2024 年 1 月 25 日)后,我无法再调试异步测试。
调试器死了
pycharm AttributeError:“ProactorEventLoop”对象没有属性“_compute_internal_coro”
我正在使用 pytest-asyncio==0.23.4 但它似乎与此无关。
我正在使用 ABAP 标准类cl_gui_textedit从选择屏幕上的文本区域读取文本。get_textstream但是在实例上调用该方法后的结果是空的。
最小工作示例:
REPORT z_mwe_textarea_bug.
DATA lr_edit TYPE REF TO cl_gui_textedit.
DATA lr_docker TYPE REF TO cl_gui_docking_container.
PARAMETERS p_dummy TYPE string DEFAULT 'just for testing'. ""// <--- need this to show selection screen.
INITIALIZATION.
CREATE OBJECT lr_docker
EXPORTING
ratio = 60.
CREATE OBJECT lr_edit
EXPORTING
parent = lr_docker.
lr_docker->dock_at( EXPORTING side = cl_gui_docking_container=>dock_at_left ).
START-OF-SELECTION.
DATA lv_text_from_textarea TYPE string.
lr_edit->get_textstream( IMPORTING text = lv_text_from_textarea ). ""// <-- why is lv_text_from_textarea empty??
Run Code Online (Sandbox Code Playgroud) 我正在尝试通过在transaction中单击“本地定义/实现”在Z_MY_LOCAL_CLASS全局类(Z_MY_GLOBAL_CLASS)中创建本地类()se24。
然后,将另一个类的源代码从其基于源代码的视图复制到单击“本地定义”按钮后显示的文本区域中。
*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
class Z_MY_LOCAL_CLASS definition
public
final
create public .
public section.
class-methods SOME_STATIC_METHOD
importing
!IS_IS type Z_SOME_TYPE
returning
value(RS_RETURN) type Z_SOME_TYPE .
protected section.
private section.
ENDCLASS.
CLASS Z_MY_LOCAL_CLASS IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method Z_MY_LOCAL_CLASS=>SOME_STATIC_METHOD
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_IN TYPE Z_SOME_TYPE
* | [<-()] RS_RETURN TYPE Z_SOME_TYPE …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我想将 JSON 数据解组到一个结构数组(一个Foo或Bar多个),所有结构都实现一个通用接口MyInterface。此外,实现该接口的所有合格结构类型都有一个公共字段,我Discrimininator在下面的示例中命名了该字段。\nDiscriminator\xc2\xb9 允许为每个 Discriminator 值唯一地找到正确的结构类型。
但在解组过程中,代码并不“知道”哪个是正确的“目标”类型。解组失败。
\n\n\n无法将对象解组为 main.MyInterface 类型的 Go 值
\n
https://play.golang.org/p/Dw1hSgUezLH
\npackage main\n\nimport (\n "encoding/json"\n "fmt"\n)\n\ntype MyInterface interface {\n // some other business logic methods go here!\n GetDiscriminator() string // GetDiscriminator returns something like a key that is unique per struct type implementing the interface\n}\n\ntype BaseStruct struct {\n Discriminator string // will always be "Foo" for all …Run Code Online (Sandbox Code Playgroud) abap ×3
go ×2
pycharm ×2
asp.net-core ×1
c# ×1
cds ×1
db2 ×1
debugging ×1
flask ×1
json ×1
json.net ×1
marshalling ×1
multi-tenant ×1
mypy ×1
pgadmin ×1
polymorphism ×1
postgresql ×1
pytest ×1
python ×1
query-string ×1
sap ×1
sqlalchemy ×1
swagger ×1