小编kon*_*tin的帖子

在 pgadmin 中创建新的本地服务器?

我在 Windows 上安装了 PostgreSQL 11 和 PGadmin 4。目前,我已连接到托管我所有数据的 AWS 服务器。

我想创建一个本地服务器 (localhost) 作为我可以进行实验的测试环境。不过,我似乎无法做到,堆栈上的其他类似问题也无济于事。这是我的过程:

  1. 在 pgAdmin 中,右键单击“服务器”并转到“创建”>“服务器”

  2. 在“创建 - 服务器”弹出框中,我输入名称:Localserver。对于“连接”,我输入 localhost。端口我保持默认'5432',db:postgres,用户名:postgres 密码:空

  3. 点击保存。

但是,我收到一个错误:

无法连接到服务器:

无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?

无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(127.0.0.1) 上运行并接受端口 5432 上的 TCP/IP 连接?

错误信息截图

我该怎么办?如果这有所作为,我是管理员。

postgresql pgadmin

30
推荐指数
2
解决办法
6万
查看次数

PyCharm 调试器因“Windows 致命异常:访问冲突”而终止

简短的介绍

我正在使用 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 \ …

debugging pycharm

17
推荐指数
1
解决办法
5788
查看次数

如何避免 mypy 检查显式排除但导入的模块_无需_手动添加 `type:ignore` (自动生成)?

在下面的 MWE 中,我有两个文件/模块:

  1. main.py这是并且应该用 mypy 检查
  2. 并且importedmodule.py不应进行类型检查,因为它是自动生成的。该文件是自动生成的,我不想添加type:ignore.

MyPy 命令

$ mypy main.py --exclude '.*importedmodule.*'
Run Code Online (Sandbox Code Playgroud)
$ mypy --version
mypy 0.931
Run Code Online (Sandbox Code Playgroud)

主要.py

"""
This should be type checked
"""

from importedmodule import say_hello

greeting = say_hello("Joe")
print(greeting)

Run Code Online (Sandbox Code Playgroud)

导入模块.py

"""
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)

python mypy

7
推荐指数
1
解决办法
7886
查看次数

当在文件中将“+”转义为“\u002b”时,从 JSON 解组“time.Time”失败,但在纯字符串中工作:无法将“\\u002b00:00\””解析为“Z07:00”

我正在解组到一个具有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)

工作示例 1:将纯 JSON 对象转换为结构

当使用纯 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)

json go unmarshalling

7
推荐指数
1
解决办法
1360
查看次数

Why does `FOR ALL ENTRIES` lower performance of CDS view on DB6?

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 …

db2 sap abap cds

6
推荐指数
1
解决办法
615
查看次数

不同的“翻译” JsonProperty名称

我想将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)

c# json.net

6
推荐指数
1
解决办法
70
查看次数

使用共享架构的 SQLAlchemy 中基于行/列的多租户

我想使用 Flask + SQLAlchemy 构建一个多租户应用程序。官方 SQLAlchemy 文档建议,要使用多租户,表应该分布在每个租户的 1 个方案上,并在引擎级别处理不同的租户。

维护多个方案对我来说似乎有点臃肿,我想知道如果设计正确,以下方法对所有租户使用相同的表是否可行,如果不是,为什么不:

  • 那些包含租户所有记录的表有一个不可为空的列tenant_id,指示哪个租户“拥有”该行。
  • Create/Update 语句(INSERTUPDATE)自动将此列的值设置为当前租户。
  • 读取/删除查询(SELECTDELETE)查询会自动WHERE tenant_id=:current tenant向 SQL添加子句/过滤器。
  • 的值tenant_id可以派生自 JSON Web 令牌。
  • 这个自动设置的值/where 子句可以在后台管理,例如通过像这个答案中的自定义会话或使用预提交钩子。

我几乎找不到关于这种方法的任何信息(除了这个名为MultiAlchemy 的软件包,它似乎与我的描述类似,但已存档且 7 年未更新)。我的直觉说,这是有原因的。

tl;dr:为什么不在 SQLAlchemy 中使用共享方案进行多租户?

sqlalchemy multi-tenant flask-sqlalchemy

6
推荐指数
1
解决办法
233
查看次数

ASP.NET Core:根据需要标记 [FromQuery] 参数

在我的控制器中,有一种方法 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(查询)被标记为可选。

我如何也将查询参数标记为必需?

query-string swagger asp.net-core

3
推荐指数
1
解决办法
6866
查看次数

为什么我的 Flask 应用程序在测试时返回状态代码为 308 的响应?

我正在对我的 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)

pytest flask

3
推荐指数
1
解决办法
1492
查看次数

PyCharm 更新到 2023.3 后无法调试异步测试

将 Pycharm 升级到 2023.3.3(内部版本 #PY-233.13763.11,构建于 2024 年 1 月 25 日)后,我无法再调试异步测试。

调试器死了

pycharm AttributeError:“ProactorEventLoop”对象没有属性“_compute_internal_coro”

我正在使用 pytest-asyncio==0.23.4 但它似乎与此无关。

pycharm

3
推荐指数
1
解决办法
194
查看次数

为什么`cl_gui_textedit-&gt;get_textstream`的结果是空的?

我正在使用 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)

abap

2
推荐指数
1
解决办法
2221
查看次数

当前CLASS POOL中PUBLIC类的名称必须为“ ...”而不是“ ...”

我正在尝试通过在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)

abap

1
推荐指数
1
解决办法
90
查看次数

Go 中类型名称处理与encoding/json 的等价性是什么?

散文简短描述

\n

我有一种情况,我想将 JSON 数据解组到一个结构数组(一个FooBar多个),所有结构都实现一个通用接口MyInterface。此外,实现该接口的所有合格结构类型都有一个公共字段,我Discrimininator在下面的示例中命名了该字段。\nDiscriminator\xc2\xb9 允许为每个 Discriminator 值唯一地找到正确的结构类型。

\n

问题和错误消息

\n

但在解组过程中,代码并不“知道”哪个是正确的“目标”类型。解组失败。

\n
\n

无法将对象解组为 main.MyInterface 类型的 Go 值

\n
\n

MWE 在

\n

https://play.golang.org/p/Dw1hSgUezLH

\n
package 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)

polymorphism marshalling go

1
推荐指数
1
解决办法
590
查看次数