Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined array key "type" on Repeater Field when using Octane in Vapor #6229

Open
msucevan opened this issue Feb 23, 2024 · 12 comments
Open
Labels
beta-feature needs more info More information is required

Comments

@msucevan
Copy link

msucevan commented Feb 23, 2024

  • Laravel Version: 10.45.1
  • Nova Version: 4.32.16
  • PHP Version: 8.3
  • Database Driver & Version:
  • Operating System and Version: AWS - Laravel Vapor

Description:

All the repeater fields are not working in Laravel Vapor.

Detailed steps to reproduce the issue on a fresh Nova installation:

Here is the implementation on one of them and the relative error:

{
"userId": 1,
"exception": {
  "class": "ErrorException",
  "message": "Undefined array key "type"",
  "code": 0,
  "file": "/var/task/vendor/laravel/nova/src/Fields/Repeater.php:241"
  },
  "aws_request_id": "feb6dff8-dd24-4529-be43-53247ad939ae"
}
Repeater implementation

Repeater::make(__('Values'), 'values')->repeatables([
    SettingsItem::make(__('Item'), 'item'),
])
    ->required()
    ->asJson(),
class SettingsItem extends Repeatable
{
    public function fields(NovaRequest $request): array
    {
        return [
            Text::make(__('Item'), 'item')
                ->rules('required'),
        ];
    }
}

This is just an example, I have over 10 Repeater fields spread around the project and everyone is failing for the same issue.

@msucevan msucevan changed the title Type Error on Repeater Field when using Laravel Vapor Undefined array key "type" on Repeater Field when using Laravel Vapor Feb 23, 2024
@crynobone
Copy link
Member

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone crynobone added needs more info More information is required beta-feature labels Feb 23, 2024
@msucevan
Copy link
Author

msucevan commented Mar 5, 2024

Yesterday I've created a new fresh project and deployed to laravel Vapor and it works fine.

However, I have the same problem all around my project. In local is working perfectly without any kind of issue, when I'm my staging or production environment I occur in this problem.

Is really strange because the payload looks good.

image

    /**
     * Format available rules.
     *
     * @return array<array-key, mixed>
     *
     * @phpstan-return array<string, TFieldValidationRules>
     */
    protected function formatRules()
    {
        $request = app(NovaRequest::class);

        if ($request->method() === 'GET') {
            return [];
        }

        return collect($request->{$this->validationKey()})
            ->map(function ($item) {
                return $this->repeatables->findByKey($item['type']); // Is failing here
            })
            ->flatMap(function (Repeatable $repeatable, $index) use ($request) {
                return FieldCollection::make($repeatable->fields($request))
                    ->mapWithKeys(function (Field $field) use ($index) {
                        return ["{$this->validationKey()}.{$index}.fields.{$field->attribute}" => $field->rules];
                    });
            })
            ->all();
    }

This is just an example, I have over 10 Repeater fields spread around the project and everyone is failing for the same issue.

@msucevan
Copy link
Author

msucevan commented Mar 7, 2024

After a few days under investigation, I realized that the problem is caused by Laravel-octane, but I have no idea why.

I will publish a reproducible repository soon @crynobone

@msucevan msucevan changed the title Undefined array key "type" on Repeater Field when using Laravel Vapor Undefined array key "type" on Repeater Field when using Octane in Vapor Mar 7, 2024
@msucevan
Copy link
Author

msucevan commented Mar 7, 2024

Please @crynobone you can fork the repo: https://github.com/msucevan/nova-issue

I will write an issue also in octane, maybe is more related with octane

Copy link

stale bot commented Mar 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 17, 2024
@msucevan
Copy link
Author

@crynobone any updates here? Should I provide more info?

@stale stale bot removed the stale label Mar 19, 2024
@numeralsix
Copy link

@msucevan I've run into a very similar issue with a nova library. Only occurs when running in the vapor environment with octane on.

ebess/advanced-nova-media-library#369

@msucevan
Copy link
Author

@msucevan I've run into a very similar issue with a nova library. Only occurs when running in the vapor environment with octane on.

ebess/advanced-nova-media-library#369

I'm not using this package. So you mean that removing this packages it works also with octane? Because in a fresh install is not working.

@crynobone
Copy link
Member

Seems to be related to #5339 (comment)

Is everyone on the same free Vapor setup?

@msucevan
Copy link
Author

@crynobone I tested using a custom domain and I have a validation error on an existing resource that don't occur when I'm not using Octane.

name: name
price: 110.0000
finishing_price: 
program_price: 
setup_price: 
factor: 1.2500
k_factors[0][type]: k-factor
k_factors[0][fields][r_t]: 1
k_factors[0][fields][k]: 2
k_factors[1][type]: k-factor
k_factors[1][fields][r_t]: 2.5
k_factors[1][fields][k]: 3.5
k_factors[2][type]: k-factor
k_factors[2][fields][r_t]: 2.5
k_factors[2][fields][k]: 2.5

"message": "The k factors.0.fields.r t field is required. (and 1 more error)",

If I send a resource where k_factors are empty or null I receive the error posted:
"message": "Undefined array key "type"",

and this is the payload:

price: 110.0000
finishing_price: 
program_price: 
setup_price: 
factor: 1.2500
k_factors[0][type]: k-factor
k_factors[0][fields][r_t]: 1
k_factors[0][fields][k]: 2```

@crynobone
Copy link
Member

CleanShot 2024-05-13 at 15 08 21

There's no r_t or k field based on the example repository

@msucevan
Copy link
Author

Let's say that this answer is pretty boring and frustrating, since doesn't change which the field name is. Of course I will not spend time and money on this issue in a fresh repository (I already give you all the information and a fresh project). I tested the custom domains on my project, the issue is reproducible in the same way as I described in a fresh install on the code that I give you. If you just seed the data inside the fields we will have the same "validation" issue, come on........

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-feature needs more info More information is required
Projects
None yet
Development

No branches or pull requests

3 participants