AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-8075540

Daniel Walker's questions

Martin Hope
Daniel Walker
Asked: 2025-03-24 23:25:46 +0800 CST

通过 FastAPI 静态提供 React 应用

  • 6

我有一个 React 应用,我正尝试通过 FastAPI 静态提供该应用。我的文件夹中有我所有的 React 构建工件static。因此,我的 FastAPI 应用如下所示:

static/
    assets/
        index-lATvXaZG.js
    index.html
app.py

在app.py中,我有:

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="react")

@app.get("")
@app.get("/")
@app.get("/index.html")
def serve_index():
    return FileResponse("static/index.html")

但是,当index.html加载时,客户端理所当然地会对 发出 GET 请求/assets/index-lATvXaZG.js。当然,FastAPI 找不到它。

我可以在我的 React 应用程序中(或者,在我的 FastAPI 设置中)进行设置以使路径对齐吗?

html
  • 2 个回答
  • 45 Views
Martin Hope
Daniel Walker
Asked: 2025-03-07 04:06:58 +0800 CST

SQLModel 上未调用字段验证器

  • 6

我有以下形式的 FastAPI 设置:

class Foo(sqlmodel.SQLModel, table=True):
    id: typing.Optional[int] = sqlmodel.Field(primary_key=True)
    data: str

    @pydantic.field_validator("data", mode="before")
    def serialize_dict(cls, value):
        if isinstance(value, dict):
            return json.dumps(value)
        return value


@app.post("/foos")
def create_foo(foo: Foo, session: sqlmodel.Session = fastapi.Depends(get_session)):
    session.add(foo)
    session.commit()
    return fastapi.Response()

然后我发布

{
    "data": {
        "bar": 5
    }
}

到/foos。但是,这会引发 SQL 异常,因为data无法绑定值。在输入一些日志语句后,我发现foo.data是dict而不是str。此外,我确认我的验证器从未被调用过。

由于SQLModel继承自pydantic.BaseModel,我本以为我可以使用这样的验证器。我遗漏了什么?

这是带有 pydantic 2.10.6 的 sqlmodel 0.0.23。

python
  • 1 个回答
  • 20 Views
Martin Hope
Daniel Walker
Asked: 2025-01-07 23:33:22 +0800 CST

引用计数未初始化的对象

  • 6

我有一些用 ARC 编译的 Objective C 代码:

void func(void) {
    NSString *string;

    // Do some stuff.  Maybe return early.

    string = @"initialized";

    // Other stuff.
}

ARC 如何处理未初始化的对象指针?我假设它像 C 指针一样,string最初包含堆栈垃圾。如果是这样,那么如果我要在初始化变量之前返回,ARC 如何知道如何处理它?

我是否需要将其初始化为,nil以避免内存泄漏?

如果引用的是调度对象或块而不是,这有关系吗NSObject?

objective-c
  • 1 个回答
  • 19 Views
Martin Hope
Daniel Walker
Asked: 2024-02-14 05:49:18 +0800 CST

不支持的 docker-compose 选项:init

  • 6

我在 Ubuntu 20.04 上运行 docker-compose 1.25.0。我的配置文件看起来像

version: "3"

services:
  foo:
    image: some_image
    init: true
    ...

当我跑步时docker-compose up,我得到

The compose file './docker-compose.yaml' is invalid because:
Unsupported config option for services.foo: 'init'

根据文档,该init选项是在 2.2 版本文件格式中添加的。据此, Compose 版本 1.13.0+ 支持该文件格式。

docker-compose
  • 1 个回答
  • 21 Views
Martin Hope
Daniel Walker
Asked: 2023-12-01 23:59:25 +0800 CST

单击文本字段后按钮无响应

  • 5

我刚刚开始 Android 应用程序开发,在实现OnClickListener. 我从 Android Studio 中的“空视图活动”开始。我在其他 UI 元素中添加了 a Button、 anEditText和ScrollView包含 a 的 a TextView。我OnClickListener在按钮上设置了一个,以便发出 logcat 消息。

当我单击该按钮时,它会按预期发出 logcat 消息。但是,一旦我单击文本字段,该按钮就会在应用程序的剩余生命周期内变得无响应。奇怪的是,如果我删除ScrollView.

这是我的 MRE:

活动主文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/startErrorText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/startButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="160dp"
        android:layout_marginTop="30dp"
        android:layout_marginEnd="160dp"
        android:text="Start"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textField" />

    <EditText
        android:id="@+id/textField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="80dp"
        android:layout_marginTop="48dp"
        android:layout_marginEnd="80dp"
        android:ems="10"
        android:hint="Enter some text"
        android:inputType="text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="409dp"
        android:layout_height="585dp"
        android:layout_marginStart="1dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="1dp"
        android:layout_marginBottom="2dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/startButton"
        app:layout_constraintVertical_bias="1.0">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/logView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.kt

package com.example.test

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.View.OnClickListener
import android.widget.Button

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val button: Button = findViewById(R.id.startButton)
        button.setOnClickListener(object : OnClickListener {
            override fun onClick(v: View?) {
                Log.i("MyApp", "Button pressed")
            }
        })
    }
}

这是 logcat 输出:

ziparchive              com.example.test                     W  Unable to open '/data/data/com.example.test/code_cache/.overlay/base.apk/classes3.dm': No such file or directory
ziparchive              com.example.test                     W  Unable to open '/data/app/~~6ohH-jaL6kb5-3S5sLz1rw==/com.example.test-21xtpoSa2I8lnFAMirvZRA==/base.dm': No such file or directory
ziparchive              com.example.test                     W  Unable to open '/data/app/~~6ohH-jaL6kb5-3S5sLz1rw==/com.example.test-21xtpoSa2I8lnFAMirvZRA==/base.dm': No such file or directory
nativeloader            com.example.test                     D  Configuring clns-6 for other apk /data/app/~~6ohH-jaL6kb5-3S5sLz1rw==/com.example.test-21xtpoSa2I8lnFAMirvZRA==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~6ohH-jaL6kb5-3S5sLz1rw==/com.example.test-21xtpoSa2I8lnFAMirvZRA==/lib/arm64, permitted_path=/data:/mnt/expand:/data/user/0/com.example.test
GraphicsEnvironment     com.example.test                     V  Currently set values for:
GraphicsEnvironment     com.example.test                     V    angle_gl_driver_selection_pkgs=[]
GraphicsEnvironment     com.example.test                     V    angle_gl_driver_selection_values=[]
GraphicsEnvironment     com.example.test                     V  ANGLE GameManagerService for com.example.test: false
GraphicsEnvironment     com.example.test                     V  com.example.test is not listed in per-application setting
GraphicsEnvironment     com.example.test                     V  Neither updatable production driver nor prerelease driver is supported.
libEGL                  com.example.test                     D  loaded /vendor/lib64/egl/libEGL_emulation.so
AppCompatDelegate       com.example.test                     D  Checking for metadata for AppLocalesMetadataHolderService : Service not found
libEGL                  com.example.test                     D  loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so
libEGL                  com.example.test                     D  loaded /vendor/lib64/egl/libGLESv2_emulation.so
om.example.test         com.example.test                     W  Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
om.example.test         com.example.test                     W  Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)
Compatibil...geReporter com.example.test                     D  Compat change id reported: 210923482; UID 10191; state: ENABLED
Compatibil...geReporter com.example.test                     D  Compat change id reported: 171228096; UID 10191; state: ENABLED
Compatibil...geReporter com.example.test                     D  Compat change id reported: 237531167; UID 10191; state: DISABLED
OpenGLRenderer          com.example.test                     W  Unknown dataspace 0
OpenGLRenderer          com.example.test                     W  Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
OpenGLRenderer          com.example.test                     W  Failed to initialize 101010-2 format, error = EGL_SUCCESS
Gralloc4                com.example.test                     I  mapper 4.x is not supported
OpenGLRenderer          com.example.test                     E  Unable to match the desired swap behavior.
AutofillManager         com.example.test                     D  notifyViewEnteredForFillDialog:1073741824
EGL_emulation           com.example.test                     D  app_time_stats: avg=145.48ms min=0.87ms max=1433.47ms count=10
EGL_emulation           com.example.test                     D  app_time_stats: avg=181.58ms min=13.65ms max=2822.69ms count=17
MyApp                   com.example.test                     I  Button pressed
ProfileInstaller        com.example.test                     D  Installing profile for com.example.test
EGL_emulation           com.example.test                     D  app_time_stats: avg=39.13ms min=0.77ms max=1255.29ms count=48
Compatibil...geReporter com.example.test                     D  Compat change id reported: 163400105; UID 10191; state: ENABLED
ImeTracker              com.example.test                     I  com.example.test:39ecb7d6: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
InputMethodManager      com.example.test                     D  showSoftInput() view=androidx.appcompat.widget.AppCompatEditText{4a6450d VFED..CL. .F.P..ID 250,132-830,256 #7f0801f9 app:id/textField aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
AssistStructure         com.example.test                     I  Flattened final assist data: 1492 bytes, containing 1 windows, 8 views
InsetsController        com.example.test                     D  show(ime(), fromIme=true)
InteractionJankMonitor  com.example.test                     D  Build configuration failed!
                                                                                                    java.lang.IllegalArgumentException: Must pass in a valid surface control if only instrument surface; 
                                                                                                        at com.android.internal.jank.InteractionJankMonitor$Configuration.validate(InteractionJankMonitor.java:1259)
                                                                                                        at com.android.internal.jank.InteractionJankMonitor$Configuration.<init>(InteractionJankMonitor.java:1217)
                                                                                                        at com.android.internal.jank.InteractionJankMonitor$Configuration.<init>(Unknown Source:0)
                                                                                                        at com.android.internal.jank.InteractionJankMonitor$Configuration$Builder.build(InteractionJankMonitor.java:1197)
                                                                                                        at com.android.internal.jank.InteractionJankMonitor.begin(InteractionJankMonitor.java:611)
                                                                                                        at android.view.inputmethod.ImeTracker$ImeJankTracker.onRequestAnimation(ImeTracker.java:717)
                                                                                                        at android.view.InsetsController$InternalAnimationControlListener$2.onAnimationStart(InsetsController.java:448)
                                                                                                        at android.animation.Animator$AnimatorListener.onAnimationStart(Animator.java:695)
                                                                                                        at android.animation.Animator$AnimatorCaller$$ExternalSyntheticLambda0.call(Unknown Source:4)
                                                                                                        at android.animation.Animator.callOnList(Animator.java:669)
                                                                                                        at android.animation.Animator.notifyListeners(Animator.java:608)
                                                                                                        at android.animation.Animator.notifyStartListeners(Animator.java:625)
                                                                                                        at android.animation.ValueAnimator.startAnimation(ValueAnimator.java:1334)
                                                                                                        at android.animation.ValueAnimator.start(ValueAnimator.java:1149)
                                                                                                        at android.animation.ValueAnimator.start(ValueAnimator.java:1173)
                                                                                                        at android.view.InsetsController$InternalAnimationControlListener.onReady(InsetsController.java:470)
                                                                                                        at android.view.InsetsAnimationThreadControlRunner.lambda$new$0(InsetsAnimationThreadControlRunner.java:129)
                                                                                                        at android.view.InsetsAnimationThreadControlRunner.$r8$lambda$3zGKYd3XPzPnvMO2hiF8a88M6T0(Unknown Source:0)
                                                                                                        at android.view.InsetsAnimationThreadControlRunner$$ExternalSyntheticLambda2.run(Unknown Source:6)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                        at android.os.Looper.loop(Looper.java:294)
                                                                                                        at android.os.HandlerThread.run(HandlerThread.java:67)
ImeTracker              com.example.test                     I  com.example.test:39ecb7d6: onShown
EGL_emulation           com.example.test                     D  app_time_stats: avg=213.12ms min=0.85ms max=500.33ms count=5
EGL_emulation           com.example.test                     D  app_time_stats: avg=500.68ms min=499.36ms max=502.83ms count=3

这种情况java.lang.IllegalArgumentException只是偶尔发生,但总体错误每次都会发生。

  • 2 个回答
  • 40 Views
Martin Hope
Daniel Walker
Asked: 2023-08-30 23:31:00 +0800 CST

malloc 属性不带参数

  • 9

我创建了一对函数:

void destroy_foo(void *ptr);
void *create_foo(void);

顾名思义,这些功能类似于malloc和free。我想使用malloc gcc 函数属性来通知编译器这种关系,以便此代码会发出警告-fanalyzer:

void *ptr = create_foo();
destroy_foo(ptr);
destroy_foo(ptr);

按照上述链接中的示例,我做了

void *create_foo(void) __attribute__ ((malloc (destroy_foo)));

虽然 gcc (11.4.0) 对此没问题,但 clang (14.0.0) 抱怨

error: 'malloc' attribute takes no arguments
void *create_foo(void) __attribute__ ((malloc (destroy_foo)));
                                       ^

我的理解是 gcc 属性与 clang 配合得很好。

c
  • 1 个回答
  • 65 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve